从Java调用WCF Web服务

时间:2016-03-09 01:08:08

标签: java wcf web service client

我在.NET中创建了一个Web服务并尝试从Java调用它,但发生以下错误:

enter image description here

我写了代码:

[ServiceBehavior(Namespace = Constants.Namespace)]
public class Service1 : IService1
{
    public int Add(int num1, int num2)
    {
        return num1 + num2;
    }

}

public class Constants
{
    // Ensures consistency in the namespace declarations across services
    public const string Namespace = "http://contoso.com/services/";
}

 [ServiceContract(Namespace = Constants.Namespace)]
public interface IService1
{

    [OperationContract]
    int Add(int num1, int num2);

}

的Web.config

<endpoint address="" binding="basicHttpBinding" contract="IService1" bindingConfiguration="defaultBasicHttpBinding" bindingNamespace="http://contoso.com/services/"/>

XML

wsdl:definitions xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"  xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:tns="http://contoso.com/services/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://contoso.com/services/" name="Service1"><wsdl:import location="http://localhost:43126/Service1.svc?wsdl=wsdl0" namespace="http://tempuri.org/"/>
<wsdl:types>
<xsd:schema targetNamespace="http://contoso.com/services/Imports">
<xsd:import namespace="http://contoso.com/services/" schemaLocation="http://localhost:43126/Service1.svc?xsd=xsd0"/>
<xsd:import namespace="http://schemas.microsoft.com/2003/10/Serialization/" schemaLocation="http://localhost:43126/Service1.svc?xsd=xsd1"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IService1_Add_InputMessage">
<wsdl:part name="parameters" element="tns:Add"/>
</wsdl:message>
<wsdl:message name="IService1_Add_OutputMessage">
<wsdl:part name="parameters" element="tns:AddResponse"/>
</wsdl:message>
<wsdl:portType name="IService1">
<wsdl:operation name="Add">
<wsdl:input message="tns:IService1_Add_InputMessage" wsaw:Action="http://contoso.com/services/IService1/Add"/>
<wsdl:output message="tns:IService1_Add_OutputMessage" wsaw:Action="http://contoso.com/services/IService1/AddResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:service name="Service1">
<wsdl:port name="BasicHttpBinding_IService1" binding="i0:BasicHttpBinding_IService1">
<soap:address location="http://localhost:43126/Service1.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

在我配置它而不使用servicecontract和servicebehavior的命名空间时,可以从Java客户端调用它。但是,使用的命名空间会导致Java出错。

使用命名空间,有没有办法从Java调用它?

0 个答案:

没有答案