如何添加XML前缀到WCF消息序列化中的字段?如何向WCF消息序列化中的字段添加XML前缀?
我连接起来,从.NET一个Java Spring的web服务,以及一个对象,我通过与参数被序列化如你所愿:
<MyClass>
<field1>Field 1 Value</field1>
<field2>Field 2 Value</field2>
</MyClass>
然而,网络服务要求类和字段前缀命名空间,假设命名空间blah
,所以我要的是:
<blah:MyClass>
<blah:field1>Field 1 Value</blah:field1>
<blah:field2>Field 2 Value</blah:field2>
</blah:MyClass>
我怎样才能做到这一点的WCF?有没有办法在我的课上调整XML序列化属性?
编辑: WSDL对于这个特定的实体如下(编辑删除特定的业务字段名,但一切是一样的):
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch0="http://www.domain.com/app/schemas/entityone" xmlns:sch1="http://www.domain.com/app/schemas/types" xmlns:sch2="http://www.domain.com/app/schemas/query" xmlns:sch3="http://www.domain.com/app/schemas/entitytwo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.domain.com/app/schemas/entityone" targetNamespace="http://www.domain.com/app/schemas/entityone">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:types="http://www.domain.com/app/schemas/types" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://www.domain.com/app/schemas/entityone" xmlns:tns="http://www.domain.com/app/schemas/entityone">
<import namespace="http://www.domain.com/app/schemas/types" />
<element name="TheClassName">
<complexType>
<sequence>
<element name="field1" type="string" />
<element name="field2" type="string" />
<element name="field3" type="string" />
<element name="field4" type="string" />
<element name="field5" type="string" />
<element name="field6" type="string" />
<element name="field7" type="string" />
<element name="field8" type="string" />
</sequence>
</complexType>
</element>
<wsdl:binding name="NameOfBindingHere" type="tns:ReturnTypeHere">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="OperationNameHere">
<soap:operation soapAction="" />
<wsdl:output name="ResponseTypeHere">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
你可以编辑这个服务的WSDL来创建一个只包含失败操作的WSDL,然后发布编辑后的WSDL?了解这是RPC还是文档服务等是非常重要的。 – 2010-09-30 19:00:23
@John,请参阅更新的问题 – Brandon 2010-09-30 19:09:40
您需要包含WSDL的其余部分。这是将声明这些名称空间声明的部分,等等。 – 2010-09-30 19:10:16