1
我有一個post方法的WCF服務。這需要一個實體。使用序列化對象調用服務方法
[OperationContract, FaultContract(typeof(ServiceError))]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped]
Entity SaveEntity(Entity entity);
我有一個帶有這些對象的xml序列化表示形式的文件。我需要能夠直接發佈這個XML到服務,而不需要在客戶端反序列化(架構問題,我們沒有引用)。
是否有可能通過像HttpClient這樣的東西構造一個請求來做到這一點?
var client = new HttpClient(HttpClient:);
client.PostAsync("http://localhost:55217/MyService.svc/SaveEntity", new HttpContent
{
Headers = new System.Net.Http.Headers.HttpContentHeaders
{
// can I put my serialised xml here?
}
}
這裏的配置:
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="MyService">
<endpoint address="" binding="webHttpBinding" contract="IMyService" behaviorConfiguration="webBehavior" bindingConfiguration="fullMessageSize" />
<endpoint address="ws" binding="wsHttpBinding" contract="IMyService" bindingConfiguration="fullMessageSize" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="fullMessageSize" maxReceivedMessageSize="104857600" />
</webHttpBinding>
<wsHttpBinding>
<binding name="fullMessageSize" maxReceivedMessageSize="104857600" />
</wsHttpBinding>
</bindings>
</system.serviceModel>
您的WCF服務是否公開RESTful端點? –
@YuvalItzchakov擴展到包含端點配置 – Liath