我想讓我的web服務用特定形式的XML進行回覆,我認爲只需將數據放入字符串並將其返回到網頁即可。從WCF服務返回原始XML
我試圖返回:
<tradeHistory><trade TradeId="1933" ExtId="1933" instrument="EUA" quantity="1500" setType="Escrow" TradeDate="12/02/2010" DeliveryDt="13/02/2010" PaymentDt="12/02/2010" type="BUY" pricePerUnit="6.81" GrossConsid="10320" currency="EUR"/></tradeHistory>
但是,當我返回字符串我越來越:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><tradeHistory><trade tradeid="1933" ExtId="1933" Instrument="EUA" quantity"1500" setType="Escrow" TradeDate="24/05/2011" DeliveryDt="25/05/2011" PaymentDt="25/05/2011" type"BUY" pricePerUnit="6.81" GrossConsid="10320" currency="EUR" /><tradeHistory></string>
我如何能實現這一目標的任何想法?這將是很好不會有標籤,但我可以忍受,但我有問題是它不是格式化字符串正確的閱讀開始和結束標記爲特殊字符
我的服務是:
<ServiceContract(Namespace:="")>
Public Interface ITradePortal
<WebGet(UriTemplate:="Reporting/GetClientTrades/{ClientID}")>
<OperationContract()>
Function GetClientTrades(ByVal ClientID As String) As String
End Interface
我的實現是:
<ServiceBehavior(ConcurrencyMode:=System.ServiceModel.ConcurrencyMode.Multiple, InstanceContextMode:=InstanceContextMode.Single, _
Namespace:="")>
<XmlSerializerFormat()>
和我的配置文件:
<services>
<service behaviorConfiguration="Default" name="CFP_Web_Lib.TradePortal">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8686/TradePortal"/>
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding"
contract="CFP_Web_Lib.ITradePortal"
behaviorConfiguration="web"
/>
<endpoint address="Operations/" binding="wsDualHttpBinding"
contract="CFP_Web_Lib.ITradeOperations"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IPubSubService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
<mexHttpBinding>
<binding name="NewBinding0" />
</mexHttpBinding>
</bindings>
你可以嘗試改變返回一個XmlElement而不是字符串的方法嗎?不知道我是否有這個WCF,雖然... – 2011-06-03 21:00:28
以上的建議是一個很好的,不管它是否足以解決整個問題:如果你要返回XML,然後返回XML,而不是一個字符串。 – 2011-06-03 21:19:37