添加服务参考正在生成消息合同 [英] Add Service Reference is generating Message Contracts

查看:114
本文介绍了添加服务参考正在生成消息合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Visual Studio 2008(SP1)上使用添加服务引用"导入给定服务时,所有请求/响应消息都不必要地包装在消息协定中(命名为->"operationName" +"Request"/响应" +最后的"1").

When I import a given service using "Add service Reference" on Visual Studio 2008 (SP1) all the Request/Response messages are being unnecessarily wrapped into Message Contracts (named as --> "operationName" + "Request"/"Response" + "1" at the end).

代码生成器说:

// CODEGEN: Generating message contract since the operation XXX is neither RPC nor 
// document wrapped.

从Java服务生成wsdl的人说他们正在指定 DOCUMENT-LITERAL/WRAPPED .

The guys who are generating the wsdl from a Java service say they are specifying DOCUMENT-LITERAL/WRAPPED.

任何帮助/指针/线索将不胜感激.

Any help/pointer/clue would be highly appreciated.

更新: 这是我的wsdl的样本,用于其中一个看起来可疑的操作.请注意,与响应相比,请求的消息元素属性不匹配.

Update: this is a sample of my wsdl for one of the operations that look suspicious. Note the mismatch on the message element attribute for the request, compared to the response.

<!- imports namespaces and defines elements -->
<wsdl:types>
  <xsd:schema targetNamespace="http://WHATEVER/" xmlns:xsd_1="http://WHATEVER_1/" xmlns:xsd_2="http://WHATEVER_2/">
      <xsd:import namespace="http://WHATEVER_1/" schemaLocation="WHATEVER_1.xsd"/>
      <xsd:import namespace="http://WHATEVER_2/" schemaLocation="WHATEVER_2.xsd"/>
      <xsd:element name="myOperationResponse" type="xsd_1:MyOperationResponse"/>
      <xsd:element name="myOperation" type="xsd_1:MyOperationRequest"/>
   </xsd:schema>
</wsdl:types>

<!- declares messages - NOTE the mismatch on the request element attribute compared to response -->
<wsdl:message name="myOperationRequest">
   <wsdl:part element="tns:myOperation" name="request"/>
</wsdl:message>
<wsdl:message name="myOperationResponse">
   <wsdl:part element="tns:myOperationResponse" name="response"/>
</wsdl:message>

<!- operations -->
<wsdl:portType name="MyService">
   <wsdl:operation name="myOperation">
      <wsdl:input message="tns:myOperationRequest"/>
      <wsdl:output message="tns:myOperationResponse"/>
      <wsdl:fault message="tns:myOperationFault" name="myOperationFault"/>
      <wsdl:fault message="tns:myOperationFault1" name="myOperationFault1"/>
   </wsdl:operation>
</wsdl:portType>

更新2 :我将导入的命名空间中的所有类型(它们都位于单独的xsd中)拉到了wsdl中,因为我怀疑导入可能会触发消息协定的生成.令我惊讶的是,事实并非如此,并且在wsdl中定义了所有类型并没有什么改变.

Update 2: I pulled all the types that I had in my imported namespace (they were in a separate xsd) into the wsdl, as I suspected the import could be triggering the message contract generation. To my surprise it was not the case and having all the types defined in the wsdl did not change anything.

然后,我(出于绝望)开始从头开始构建wsdls,并使用序列属性中包含的元素属性的maxOccurs属性,从而能够重现不希望的消息协定生成行为.

I then (out of desperation) started constructing wsdls from scratch and playing with the maxOccurs attributes of element attributes contained in a sequence attribute I was able to reproduce the undesired message contract generation behavior.

这是元素的示例:

<xsd:element name="myElement">
   <xsd:complexType>
      <xsd:sequence>
         <xsd:element minOccurs="0" maxOccurs="1" name="arg1" type="xsd:string"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:element>

在用作消息的元素(基本上是所有请求和响应)上玩maxOccurs时,会发生以下情况:

Playing with maxOccurs on elements that are used as messages (all requests and responses basically) the following happens:

  • maxOccurs ="1"不会触发换行
  • macOcccurs> 1 触发包装
  • maxOccurs ="unbounded" 触发包装
  • maxOccurs = "1" does not trigger the wrapping
  • macOcccurs > 1 triggers the wrapping
  • maxOccurs = "unbounded" triggers the wrapping

我还不能在生产的wsdl中复制它,因为类型的嵌套非常深,这将花费我一些时间进行彻底检查.同时,我希望它可能会敲响铃铛-非常感谢您的帮助.

I was not able to reproduce this on my production wsdl yet because the nesting of the types goes very deep, and it's gonna take me time to inspect it thoroughly. In the meanwhile I am hoping it might ring a bell - any help highly appreciated.

推荐答案

我遇到了同样的问题,并解决了这个问题.

I had this same issue and this solved it.

我用了这个

    <wsdl:message name="Method">
      <wsdl:part name="parameters" element="s0:Method"/>
    </wsdl:message>

    <wsdl:message name="MethodResponse">
      <wsdl:part name="parameters" element="s0:MethodResponse"/>
    </wsdl:message>

代替:

    <wsdl:message name="Method">
      <wsdl:part name="request" element="s0:Method"/>
    </wsdl:message>

    <wsdl:message name="MethodResponse">
      <wsdl:part name="response" element="s0:MethodResponse"/>
    </wsdl:message>

我相信有人之前提到过它,但我还不能对他们的答案进行投票!

I believe someone mentioned it before but I can't upVote their answer yet!

这篇关于添加服务参考正在生成消息合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆