如何修改wsdl的名称和元素属性:WCF中的一部分?
How to modify name and element attributes of wsdl: part in WCF?
看似简单,但是对于wsdl:part
的element和name属性,我真的是一头雾水。这是 C#:
中服务代码的一部分
接口:
[ServiceContract(Namespace = "http://example.org/virtualfoo")]
public interface IRestFooService
{
[OperationContract]
[WebInvoke(UriTemplate = "getFoo", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
getFooResponseMess getFoo(getFooRequest request);
}
服务:
[ServiceBehavior(Namespace = "http://example.org/virtualfoo")]
public class RestFooService: IRestFooService
{
public getFooResponseMess getFoo(getFooRequest request)
{
// code
}
}
复杂类型:
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class getFooResponseMess
{
[System.ServiceModel.MessageBodyMember(Namespace = "http://example.org/virtualfoo")]
public getFooResponse getFooResponse;
public getFooResponseMess()
{
}
public getFooResponseMess(getFooResponse getFooRes)
{
this.getFooResponse = getFooRes;
}
}
getFooResponse
class是另一种复杂类型(自定义class)
我有一个 WCF 但是当我看到 wsdl 结构时我想区分或自定义这部分:
我有这个:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponse" name="getFooResponse"/>
</wsdl:message>
...
但我想要这个:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponse" name="getFooResult"/>
</wsdl:message>
...
显然,如果我更改复杂类型 (getFooResponseMess
) 的 class 的 属性 名称,它会同时更改 name
和 element
属性:
[System.ServiceModel.MessageBodyMember(Namespace = "http://example.org/virtualfoo")]
public getFooResponse getFooResponseTest; // Change
Wsdl 输出:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponseTest" name="getFooResponseTest"/>
</wsdl:message>
...
但是有可能有不同的值吗?我该怎么做?我想知道我的错误是什么以及为什么会这样
我已经寻找了其他问题,但这个问题的解决方案对我的情况不起作用:Changing wsdl:part name
WCF 允许您使用 XML 的遗留 SOAP 编码样式,但是,不推荐使用它。使用此样式时(通过在应用于服务合同的 System.ServiceModel.XmlSerializerFormatAttribute 上将使用 属性 设置为编码),以下附加注意事项适用:
不支持消息headers;这意味着属性 MessageHeaderAttribute 和数组属性 MessageHeaderArrayAttribute 与 SOAP 编码不兼容。
如果消息契约不被包装,即如果属性 IsWrapped设置为false,消息契约只能有一个body部分。
请求消息协定的包装元素名称必须与操作名称相匹配。为此使用消息协定的 WrapperName 属性。
响应消息契约的包装元素名称必须与后缀为'Response'的操作名称相同。为此使用消息协定的 WrapperName 属性。
看似简单,但是对于wsdl:part
的element和name属性,我真的是一头雾水。这是 C#:
接口:
[ServiceContract(Namespace = "http://example.org/virtualfoo")]
public interface IRestFooService
{
[OperationContract]
[WebInvoke(UriTemplate = "getFoo", Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
getFooResponseMess getFoo(getFooRequest request);
}
服务:
[ServiceBehavior(Namespace = "http://example.org/virtualfoo")]
public class RestFooService: IRestFooService
{
public getFooResponseMess getFoo(getFooRequest request)
{
// code
}
}
复杂类型:
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class getFooResponseMess
{
[System.ServiceModel.MessageBodyMember(Namespace = "http://example.org/virtualfoo")]
public getFooResponse getFooResponse;
public getFooResponseMess()
{
}
public getFooResponseMess(getFooResponse getFooRes)
{
this.getFooResponse = getFooRes;
}
}
getFooResponse
class是另一种复杂类型(自定义class)
我有一个 WCF 但是当我看到 wsdl 结构时我想区分或自定义这部分:
我有这个:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponse" name="getFooResponse"/>
</wsdl:message>
...
但我想要这个:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponse" name="getFooResult"/>
</wsdl:message>
...
显然,如果我更改复杂类型 (getFooResponseMess
) 的 class 的 属性 名称,它会同时更改 name
和 element
属性:
[System.ServiceModel.MessageBodyMember(Namespace = "http://example.org/virtualfoo")]
public getFooResponse getFooResponseTest; // Change
Wsdl 输出:
...
<wsdl:message name="getFooResponseMess">
<wsdl:part element="tns:getFooResponseTest" name="getFooResponseTest"/>
</wsdl:message>
...
但是有可能有不同的值吗?我该怎么做?我想知道我的错误是什么以及为什么会这样
我已经寻找了其他问题,但这个问题的解决方案对我的情况不起作用:Changing wsdl:part name
WCF 允许您使用 XML 的遗留 SOAP 编码样式,但是,不推荐使用它。使用此样式时(通过在应用于服务合同的 System.ServiceModel.XmlSerializerFormatAttribute 上将使用 属性 设置为编码),以下附加注意事项适用:
不支持消息headers;这意味着属性 MessageHeaderAttribute 和数组属性 MessageHeaderArrayAttribute 与 SOAP 编码不兼容。
如果消息契约不被包装,即如果属性 IsWrapped设置为false,消息契约只能有一个body部分。
请求消息协定的包装元素名称必须与操作名称相匹配。为此使用消息协定的 WrapperName 属性。
响应消息契约的包装元素名称必须与后缀为'Response'的操作名称相同。为此使用消息协定的 WrapperName 属性。