我看过很多关于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>