[英]Silverlight Custom Binding from CodeBehind
我已經看到了許多有關WShttpbinding
和Silverlight
的示例。 另外,我成功地運行了該應用程序,但必須從后面的代碼創建自定義綁定。
我已經嘗試過了,但是出現如下錯誤:
In Binding 'MyCustom', TransportBindingElement 'HttpsTransportBindingElement' does not
appear last in the BindingElementCollection. Please change the order of elements such
that the TransportBindingElement is last.
碼
public static MyTempService.ServiceClient WCFServiceClient()
{
{
EndpointAddressBuilder AddressBuilder = new EndpointAddressBuilder(new EndpointAddress("https://node94.MyWab.local:8089/WcfService/Service.svc"));
CustomBinding Cusbinding = new CustomBinding
("MyCustom",
"MyTempService",
SecurityBindingElement.CreateUserNameOverTransportBindingElement(),
new BinaryMessageEncodingBindingElement(),
new HttpsTransportBindingElement()
);
Cusbinding.Elements.Add(new TextMessageEncodingBindingElement()
{
MessageVersion = System.ServiceModel.Channels.MessageVersion.Default,
WriteEncoding = System.Text.Encoding.UTF8
});
Cusbinding.OpenTimeout = new TimeSpan(0, 5, 0);
Cusbinding.CloseTimeout = new TimeSpan(0, 5, 0);
Cusbinding.ReceiveTimeout = new TimeSpan(0, 5, 0);
Cusbinding.SendTimeout = new TimeSpan(0, 5, 0);
return new MyTempService.ServiceClient(Cusbinding, AddressBuilder.ToEndpointAddress());
}
}
服務配置文件
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
<endToEndTracing propagateActivity="true" activityTracing="true"
messageFlowTracing="true" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="WsBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WsBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="false"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="WsBehaviour" name="Service">
<endpoint address="https://node94.MyWeb.local:8089/WcfService/Service.svc"
binding="wsHttpBinding" bindingConfiguration="WsBinding" contract="IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
當我查看您的代碼時,我看到BindingElementCollection中的最后一個是
TextMessageEncodingBindingElement()
按照以下方式嘗試:
1)從構造器中刪除新的HttpsTransportBindingElement()
2)將此元素添加為之后的最后一個元素
Cusbinding.Elements.Add(new TextMessageEncodingBindingElement()
{
MessageVersion = System.ServiceModel.Channels.MessageVersion.Default,
WriteEncoding = System.Text.Encoding.UTF8
});
Cusbinding.Elements.Add(new HttpsTransportBindingElement());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.