c#引用一个java写的wsdl,调用服务里的一个返回值为string 的方法,报以下异常:
{"接收对 http://172.17.175.162/swsso/services/SsoWebService 的 HTTP 响应时发生错误。这可能是由于服务终结点绑定未使用 HTTP 协议造成的。这还可能是由于服务器中止了 HTTP 请求上下文(可能由于服务关闭)所致。有关详细信息,请参见服务器日志。"}
http://172.17.175.162/swsso/services/SsoWebService 这是一个只能内网调用的服务,
引用后web.config自动产生的配置
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SsoWebServiceSoapBinding" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://172.17.175.162/swsso/services/SsoWebService"
binding="basicHttpBinding" bindingConfiguration="SsoWebServiceSoapBinding"
contract="MySsoServiceReference.SsoWebService" name="SsoWebServiceImplPort" />
</client>
</system.serviceModel>
服务器用的是 windows server pack 2 IIS 用的7.0
调用方法的代码是
var ssows = new MySsoServiceReference.SsoWebServiceClient();
ssows.Open();
string result = ssows.appLoginEx1(appCode, ticket);//这里异常报错,方法的传入参数都是string
ssows.Close();
网上看了好多解决方案,测试了都不行,希望那个前辈能指教一下!
建议用storm webservice工具测试一下服务
您方便的话+920459507 QQ聊下
找到错误了,接口的输入参数虽然是string ,但是要是特定的格式的string 比如guid.ToString(),坑爹的接口,只写了参数类型是string 没写具体的要求
首先确认该方法可以直接在浏览器里面看到
http://172.17.175.162/swsso/services/SsoWebService?wsdl
如果不行找对方。
直接输入服务地址在浏览器是能看到服务的
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://webservice.sso.sunyway.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="SsoWebService" targetNamespace="http://webservice.sso.sunyway.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://webservice.sso.sunyway.com/" elementFormDefault="unqualified" targetNamespace="http://webservice.sso.sunyway.com/" version="1.0">
<xs:element name="appLogin" type="tns:appLogin"/>
<xs:element name="appLoginEx" type="tns:appLoginEx"/>
<xs:element name="appLoginEx1" type="tns:appLoginEx1"/>
<xs:element name="appLoginEx1Response" type="tns:appLoginEx1Response"/>
<xs:element name="appLoginEx2" type="tns:appLoginEx2"/>
<xs:element name="appLoginEx2Response" type="tns:appLoginEx2Response"/>
<xs:element name="appLoginExResponse" type="tns:appLoginExResponse"/>
<xs:element name="appLoginResponse" type="tns:appLoginResponse"/>
<xs:complexType name="appLoginEx1">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginEx1Response">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginEx">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
<xs:element minOccurs="0" name="arg2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginExResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:ssoUserView"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ssoUserView">
<xs:complexContent>
<xs:extension base="tns:ssoPersonView">
<xs:sequence>
<xs:element minOccurs="0" name="accessUnitCode" type="xs:string"/>
<xs:element minOccurs="0" name="accessUnitName" type="xs:string"/>
<xs:element minOccurs="0" name="isAdmin" type="xs:boolean"/>
<xs:element minOccurs="0" name="isDelete" type="xs:boolean"/>
<xs:element minOccurs="0" name="personId" type="xs:long"/>
<xs:element minOccurs="0" name="personType" type="xs:int"/>
<xs:element minOccurs="0" name="postIds" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="roleIds" nillable="true" type="xs:long"/>
<xs:element minOccurs="0" name="usbKey" type="xs:string"/>
<xs:element minOccurs="0" name="userAccount" type="xs:string"/>
<xs:element minOccurs="0" name="userActive" type="xs:boolean"/>
<xs:element minOccurs="0" name="userName" type="xs:string"/>
<xs:element minOccurs="0" name="userPwd" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ssoPersonView">
<xs:sequence>
<xs:element minOccurs="0" name="address" type="xs:string"/>
<xs:element minOccurs="0" name="birthday" type="xs:string"/>
<xs:element minOccurs="0" name="credNo" type="xs:string"/>
<xs:element minOccurs="0" name="credType" type="xs:string"/>
<xs:element minOccurs="0" name="degree" type="xs:string"/>
<xs:element minOccurs="0" name="duties" type="xs:string"/>
<xs:element minOccurs="0" name="education" type="xs:string"/>
<xs:element minOccurs="0" name="email" type="xs:string"/>
<xs:element minOccurs="0" name="fax" type="xs:string"/>
<xs:element minOccurs="0" name="fixedTel" type="xs:string"/>
<xs:element minOccurs="0" name="mobileTel" type="xs:string"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
<xs:element minOccurs="0" name="nativeplace" type="xs:string"/>
<xs:element minOccurs="0" name="officeTel" type="xs:string"/>
<xs:element minOccurs="0" name="oid" type="xs:long"/>
<xs:element minOccurs="0" name="personOrder" type="xs:int"/>
<xs:element minOccurs="0" name="pinyin" type="xs:string"/>
<xs:element minOccurs="0" name="pinyinSimple" type="xs:string"/>
<xs:element minOccurs="0" name="political" type="xs:string"/>
<xs:element minOccurs="0" name="postcode" type="xs:string"/>
<xs:element minOccurs="0" name="sex" type="xs:string"/>
<xs:element minOccurs="0" name="status" type="xs:int"/>
<xs:element minOccurs="0" name="unitId" type="xs:long"/>
<xs:element minOccurs="0" name="unitName" type="xs:string"/>
<xs:element minOccurs="0" name="virtualTel" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLogin">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:ssoUserView"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginEx2">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
<xs:element minOccurs="0" name="arg2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="appLoginEx2Response">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="appLoginEx">
<wsdl:part element="tns:appLoginEx" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginEx1Response">
<wsdl:part element="tns:appLoginEx1Response" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginEx1">
<wsdl:part element="tns:appLoginEx1" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginEx2">
<wsdl:part element="tns:appLoginEx2" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLogin">
<wsdl:part element="tns:appLogin" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginExResponse">
<wsdl:part element="tns:appLoginExResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginResponse">
<wsdl:part element="tns:appLoginResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="appLoginEx2Response">
<wsdl:part element="tns:appLoginEx2Response" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="SsoWebService">
<wsdl:operation name="appLoginEx1">
<wsdl:input message="tns:appLoginEx1" name="appLoginEx1"></wsdl:input>
<wsdl:output message="tns:appLoginEx1Response" name="appLoginEx1Response"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLoginEx">
<wsdl:input message="tns:appLoginEx" name="appLoginEx"></wsdl:input>
<wsdl:output message="tns:appLoginExResponse" name="appLoginExResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLogin">
<wsdl:input message="tns:appLogin" name="appLogin"></wsdl:input>
<wsdl:output message="tns:appLoginResponse" name="appLoginResponse"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLoginEx2">
<wsdl:input message="tns:appLoginEx2" name="appLoginEx2"></wsdl:input>
<wsdl:output message="tns:appLoginEx2Response" name="appLoginEx2Response"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SsoWebServiceSoapBinding" type="tns:SsoWebService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="appLoginEx1">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="appLoginEx1">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="appLoginEx1Response">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLogin">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="appLogin">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="appLoginResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLoginEx">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="appLoginEx">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="appLoginExResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="appLoginEx2">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="appLoginEx2">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="appLoginEx2Response">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SsoWebService">
<wsdl:port binding="tns:SsoWebServiceSoapBinding" name="SsoWebServiceImplPort">
<soap:address location="http://172.17.175.162/swsso/services/SsoWebService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
绑定由basicHttpBinding改为wsHttpBinding试试
改过之后报{"system.serviceModel/bindings/wsHttpBinding 处的绑定没有名称为“SsoWebServiceSoapBinding”的已配置绑定。对于 bindingConfiguration,该值无效。 (E:\\单点登录\\SAJDL\\SAJDL\\web.config line 20)"}
@金正声: 怀疑和你贴的自动生成的客户端代码没有关系。SOAP协议是互联系统的通用标准,直接感觉是.NET引用有错误,或者是Java的服务端配置有问题。你可以试一下WCF客户端引用该web服务试试。
@JeffWong: 问题找到了,是参数的类型问题,我传的参数和服务器要求的参数不一致,对方服务器异常了就直接抛出了,没有抛出错误信息,客户端接收不到抛出的信息
@金正声: 我之前刚刚碰到过,客户端自动生成代码确实都没有问题,通常都是服务端的问题。
@JeffWong:写接口的人坑爹,错误就直接抛出了,也不写错误信息,坑了我一个星期......
如果用java客户端来连是对的,用c#就出错的话,可以先看看在c#调用时的日子有没有错误记录。
或是写个无参方法测试下看是否能正常调用。
这种异构平台服务调用不成功,多半是编码不一致造成的。比如utf-8,gb312什么的,各自不一样。
如果明了java那边的编码,那把c#这边强制设定下编码。
JAVA那边的编码是utf-8
我把接收的值编号了 还是报原来那个错
string result = Encoding.GetEncoding("UTF-8").GetBytes(ssows.appLoginEx1(appCode, ticket)).ToString();//返回值
WCF客户端测试看看
问题已经解决了,谢谢!
建议先使用soapui 测试
请问这个问题你们是怎么解决的,我现在也遇到了这个问题,方便告知一下吗?