首页 新闻 会员 周边

asp.net调用Java开发wsdl接口出现客户端发现响应内容类型为“multipart/related; 应为text/xml

0
悬赏园豆:200 [已解决问题] 解决于 2016-03-03 18:36

asp.net调用Java开发wsdl接口出现客户端发现响应内容类型为“multipart/related; 应为text/xml

有人知道怎解决这个办法吗?求高手指教!

在soapui上测试是正常的,如下的请求头部信息

POST https://ws.colissimo.fr/sls-ws/SlsServiceWS HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 896
Host: ws.colissimo.fr
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

发出的XML为下面

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sls="http://sls.ws.coliposte.fr">
   <soapenv:Header/>
   <soapenv:Body>
      <sls:getProductInter>
         <!--Optional:-->
         <getProductInterRequest>
            <contractNumber>824930</contractNumber>
            <password>parisezhan2016</password>
            <productCode>COLI</productCode>
            <!--Optional:-->
            <insurance>0</insurance>
            <!--Optional:-->
            <nonMachinable>0</nonMachinable>
            <!--Optional:-->
            <returnReceipt>0</returnReceipt>
            <!--Optional:-->
            <countryCode>DZ</countryCode>
            <!--Optional:-->
            <zipCode>2000</zipCode>
            <!--Optional:-->
            <city>CC</city>
         </getProductInterRequest>
      </sls:getProductInter>
   </soapenv:Body>
</soapenv:Envelope>

 

得出的返回结果是下面

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:getProductInterResponse xmlns:ns2="http://sls.ws.coliposte.fr">
         <return>
            <messages>
               <id>30008</id>
               <messageContent>Service compte client</messageContent>
               <type>ERROR</type>
            </messages>
         </return>
      </ns2:getProductInterResponse>
   </soap:Body>
</soap:Envelope>

 

但在asp.net调用, 不管怎样设置总有“multipart/related; 应为text/xml返回错误再加上请求的内容。

“System.InvalidOperationException”类型的未经处理的异常在 System.Web.Services.dll 中发生 

其他信息: 客户端发现响应内容类型为“multipart/related; type="application/xop+xml"; boundary="uuid:8b21dd1e-c61f-4587-99a6-06036d7f99ad"; start="<root.message@cxf.apache.org>"; start-info="text/xml"”,但应为“text/xml”。

请求失败,错误信息为:

--

--uuid:8b21dd1e-c61f-4587-99a6-06036d7f99ad

Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";

Content-Transfer-Encoding: binary

Content-ID: <root.message@cxf.apache.org>



<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:getProductInterResponse xmlns:ns2="http://sls.ws.coliposte.fr"><return><messages><id>30008</id><messageContent>Service compte client</messageContent><type>ERROR</type></messages></return></ns2:getProductInterResponse></soap:Body></soap:Envelope>

--uuid:8b21dd1e-c61f-4587-99a6-06036d7f99ad--

--.

 

求大家帮忙解答, 这个例子的wsdl接口如下

https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl

 

经过几天的折腾, 用JAVA测试了一下,只用了半个小时就成功了。 用专用的.net工具也测试不成功, 可能是服务器那边不支持.net访问, 但他们说是支持的。 折腾呀

风浪的主页 风浪 | 老鸟四级 | 园豆:2996
提问于:2016-02-26 20:00
< >
分享
最佳答案
0

.net中服务引用地址中?wsdl不能少

收获园豆:200
jello chen | 大侠五级 |园豆:7336 | 2016-02-27 02:09

不是, 在sopui测试一点问题也没有, asp.net调用java开发的接口, 这个问题还是不知道怎解决, 没有一些明确的方案,主要是异常追踪不出, 出错的原因在哪里。

风浪 | 园豆:2996 (老鸟四级) | 2016-02-29 17:31

@风浪: http://blog.csdn.net/gd2008/article/details/41681355

jello chen | 园豆:7336 (大侠五级) | 2016-02-29 23:55
jello chen | 园豆:7336 (大侠五级) | 2016-03-01 08:59

@jello chen: 

C# 还是实现不成功,WebserviceStudio20这个web service工具测试都报错, 没办法, 只能改用java来做了, 但这个项目其它的模块已经做好了, 为了.net方便开发, 造成现在的问题, 只能用java再做一个服务,通过接口收了数据, 再把数据传给这个web service, 但不能保证数据中转这么多次, 数据处理总会存在问题, 你研究这方面的, 可以帮我试一下我问题的这个接口吗?

风浪 | 园豆:2996 (老鸟四级) | 2016-03-02 11:43

@风浪: 试了下https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl你这个,是可以的。步骤如下:右键项目--添加服务引用--高级--添加Web引用--在URL处输入wsdl地址,点击右侧按钮前往--在右侧中会解析出服务--起个Web引用名,或者默认--添加引用,然后就会在你的项目中生成客户端代理类(在Web References目录下),然后,你就可以在你的代码中使用这个代理类:

SlsServiceWS proxy = new SlsServiceWS();
//call api
jello chen | 园豆:7336 (大侠五级) | 2016-03-02 13:29

@jello chen: 

这个添加引用是可以的, 但请求一个接口时, 返回信息也是对的, 但返回信息前面有异常 ,-------其他信息: 客户端发现响应内容类型为“multipart/related;---------这一大串字符后,接着才是这个接口返回的信息

风浪 | 园豆:2996 (老鸟四级) | 2016-03-02 13:36

@风浪: 给一个调用示例代码,我试试

jello chen | 园豆:7336 (大侠五级) | 2016-03-02 14:13

@jello chen: 

try
            {
                getProductInterGetProductInterRequest frPIR = new getProductInterGetProductInterRequest();
                frPIR.contractNumber = "2016824927";
                frPIR.password = "par2016";
                frPIR.productCode = "COLI";
                frPIR.insurance = false;
                frPIR.nonMachinable = false;
                frPIR.returnReceipt = false;
                frPIR.countryCode = "DZ";
                frPIR.zipCode = "2000";
                frPIR.city = "CC";

                SlsServiceWS ws = new SlsServiceWS();
                GetProductInterResponseType gpirt = ws.getProductInter(frPIR);
                Message[] mess = gpirt.messages;
                if (mess.Length > 0)
                {
                    Response.Write("id: " + mess[0].id.ToString() + "   , message: "+ mess[0].messageContent.ToString() + "   ,type:  "+ mess[0].type.ToString());
                }
                else
                {
                    Response.Write("没有接收到返回信息!");
                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());
            }            

 

请求后,返回是的异常+结果, 下面红色的为请求到的结果

客户端发现响应内容类型为“multipart/related; type="application/xop+xml"; boundary="uuid:6ec0582b-a869-4164-8cee-3517aaa38648"; start="<root.message@cxf.apache.org>"; start-info="text/xml"”,但应为“text/xml”。 请求失败,错误信息为: -- --uuid:6ec0582b-a869-4164-8cee-3517aaa38648 Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"; Content-Transfer-Encoding: binary Content-ID: <root.message@cxf.apache.org>30008Service non autoris?? pour cet identifiant. Veuillez prendre contact avec votre interlocuteur commercial afin de r??initialiser votre compte clientERROR --uuid:6ec0582b-a869-4164-8cee-3517aaa38648-- --.

风浪 | 园豆:2996 (老鸟四级) | 2016-03-02 14:26

@风浪: 需要身份验证,没法儿测试你的代码,试试这样:

<configuration>  
<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="SlsServiceWSSoapBinding">
          <mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          </mtomMessageEncoding>
        </binding>
      </customBinding>
    </bindings>
  </system.serviceModel>
</configuration>

把红色标记的部分copy到你的app.config或者web.config的configuration节点下,重新生成,再运行试试

jello chen | 园豆:7336 (大侠五级) | 2016-03-02 14:44

@jello chen: 

不需要身份验证呀, 就是这样提交一个getProductInterGetProductInterRequest, 返回一个GetProductInterResponseType类型, 在asp.net不知怎么总提示客户端发现响应内容类型为“multipart/related,但应为“text/xml”,  我在java中,测试是成功的, 也是这样的, 在.NET中总提示异常

JAVA请求得出的是正常的

 

System.out.println("id: "+mmm[0].getId()  + ",type: "+mmm[0].getType() + ",message: "+mmm[0].getMessageContent());

id: 30008,
type: ERROR,
message: Service non autorisé pour cet identifiant. Veuillez prendre contact avec votre interlocuteur commercial afin de réinitialiser votre compte client

 

 

风浪 | 园豆:2996 (老鸟四级) | 2016-03-02 15:05

@风浪: 用WSE3.0可以解决你这个问题,亲测

jello chen | 园豆:7336 (大侠五级) | 2016-03-03 10:17

@风浪: 步骤如下:

1.安装WSE3.0,地址:WSE 3.0.

2.使用WSE Configuration Tool(安装路径下)使你的.net项目启用WSE.

3.添加对Microsoft.Web.Services3.dll的引用.

4.把下面配置copy到(app|web).config文件中configuration节点下

<microsoft.web.services3>
    <messaging>
        <mtom serverMode="optional"  clientMode="On"  />
    </messaging>
  </microsoft.web.services3>

5.添加web引用

6.选中项目,显示所有文件,在Web References目录下找到Reference.cs,修改SlsServiceWS继承自Microsoft.Web.Services3.WebServicesClientProtocol

7.编写调用代码

8.重新生成,运行

jello chen | 园豆:7336 (大侠五级) | 2016-03-03 10:38

@风浪: 可以找个WSE 3.0的使用,比如找个,你这个不需要证书啊什么的,只需要使你的项目启用WSE即可

jello chen | 园豆:7336 (大侠五级) | 2016-03-03 10:43

@jello chen: 

对的, 这个办法是可以直接访问, 返回正确的数据了, 十分感谢!

风浪 | 园豆:2996 (老鸟四级) | 2016-03-03 18:35
其他回答(1)
0

(1)确定你添加的WSDL引用是否是【服务引用】而非【Web引用】

(2)如果确定添加的是服务引用,然后尝试使用添加引用创建的【代理类】

参考网址:WSDL file from JAVA AXIS

Jeffcky | 园豆:2789 (老鸟四级) | 2016-02-26 23:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册