请帮助使用Java客户端进行C#WCF服务,该服务正在抛出:
线程“main”中的异常javax.xml.ws.WebServiceException:未定义的端口类型:{http://tempuri.org/} WCFService at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 在javax.xml.ws.Service.getPort(未知来源) 在Client.main(Client.java:20)
```
这是Java Code Snippet:
import java.net.URL;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
public class Client {
@WebService(name = "WCFService", targetNamespace = "http://tempuri.org/")
public interface IWCFService {
@WebMethod
String Echo(String input);
}
public static void main(String[] args) throws Exception {
QName port = new QName("http://tempuri.org/", "WCFService");
URL location = new URL("http://localhost:8000/WCFService?wsdl");
Service serv = Service.create(location, port);
IWCFService p = serv.getPort(IWCFService.class);
System.out.println(p.Echo("Hello World!"));
}
}
以下是WCF代码段:
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
namespace WCFWSDL
{
public class Program
{
[ServiceContract]
public interface IWCFService
{
[OperationContract]
string Echo(string input);
}
public class WCFService : IWCFService
{
public string Echo(string input) { return "Your input: " + input; }
}
public static void Main()
{
string baseAddress = "http://localhost:8000/WCFService";
ServiceHost host = new ServiceHost(typeof(WCFService), new Uri(baseAddress));
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(typeof(IWCFService), new BasicHttpBinding(), "");
host.Open();
Console.WriteLine("http://localhost:8000/WCFService?wsdl");
Console.WriteLine("Press ENTER to close");
Console.ReadLine();
host.Close();
}
}
}
由于