Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Java调用WCF Web服务_Java_Wcf_Web_Service_Client - Fatal编程技术网

从Java调用WCF Web服务

从Java调用WCF Web服务,java,wcf,web,service,client,Java,Wcf,Web,Service,Client,我在.NET中创建了一个web服务,并尝试从Java调用它,但出现以下错误: 我写了代码: [ServiceBehavior(Namespace = Constants.Namespace)] public class Service1 : IService1 { public int Add(int num1, int num2) { return num1 + num2; } } public class Constants { // E

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

我写了代码:

[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”>
当我配置它时,可以从Java客户机调用它,而不使用servicecontract和servicebehavior的名称空间。但是,正是使用名称空间导致了Java中的错误


使用名称空间,有没有从Java调用它的方法?

我不能确定,但我认为必须填写端点地址。如何配置Web.config?我不能确定,但我认为必须填写端点地址。如何配置Web.config?
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>