我使用Vaster Clemens教程创建了一个示例xmlrpc C#server-client
http://vasters.com/clemensv/PermaLink,guid,679ca50b-c907-4831-81c4-369ef7b85839.aspx
我已成功连接到C#服务器到C#客户端,但每当我尝试使用Java客户端连接到C#服务器时,我只会收到此错误:
HTTP服务器返回意外状态:内部服务器错误
以下是公开的C#服务器API:
[ServiceContract]
public interface ITestAPI {
[OperationContract(Action = "test.returnSum")]
int returnSum(
int a,
int b);
这是服务器部分:
Uri baseAddress = new UriBuilder(Uri.UriSchemeHttp, Environment.MachineName, 8080, "/testDemo/").Uri;
ServiceHost serviceHost = new ServiceHost(typeof(TestAPI));
var epXmlRpc = serviceHost.AddServiceEndpoint(typeof(ITestAPI), new WebHttpBinding(WebHttpSecurityMode.None), new Uri(baseAddress, "./test"));
epXmlRpc.Behaviors.Add(new XmlRpcEndpointBehavior());
serviceHost.Open();
Console.ReadLine();
serviceHost.Close();
C#客户端来到这里:
Uri blogAddress = new UriBuilder(Uri.UriSchemeHttp, Environment.MachineName, PORT_NUMBER, pathValue).Uri;
ChannelFactory<ITestAPI> testAPIFactory = new ChannelFactory<ITestAPI>(new WebHttpBinding(WebHttpSecurityMode.None), new EndpointAddress(blogAddress));
testAPIFactory.Endpoint.Behaviors.Add(new XmlRpcEndpointBehavior());
testAPI = testAPIFactory.CreateChannel();
testAPI.returnSum(1,2);
在此之后,我尝试实现此处给出的示例Java XML-RPC客户端,并尝试将其连接到正在运行的C#服务器
http://www.tutorialspoint.com/xml-rpc/xml_rpc_examples.htm
public class JavaClient {
public static void main (String [] args) {
try {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:8080/testDemo/test"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Vector params = new Vector();
params.addElement( new Integer(5) );
params.addElement( new Integer(5) );
Integer result = (Integer)client.execute( "returnSum", params );
if ( result != null )
System.out.println( "result" + result);
} catch (XmlRpcException exception) {
System.err.println("JavaClient: XML−RPC Fault #" +
Integer.toString(exception.code) + ": " +
exception.toString());
} catch (Exception exception) {
System.err.println("JavaClient: " + exception.toString());
}
}
}
没有任何作用。
非常感谢任何形式的帮助。
答案 0 :(得分:1)
我能够解决这个问题:API应该像这样调用:client.execute(&#34; test.returnSum&#34;,params);来自你的客户。即你在操作合同中提到的相同字符串。