gpt4 book ai didi

wcf - [Silverlight] WCF 客户端的编程配置

转载 作者:行者123 更新时间:2023-12-04 00:26:05 24 4
gpt4 key购买 nike

我们正在将 Silverlight 客户端开发到通过 WCF 公开的基于服务器的 API 上。

我正在尝试将我的 WCF 客户端代码(运行良好)从基于配置的模型转移到编程模型。这将使我拥有一个单一的“根”URL,我可以在启动时应用它,而不需要安装必须维护庞大的配置文件。

不过,我正在努力将我的配置转换为支持 Silverlight 的代码。

我的其中一项服务有以下配置:

<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinding_ISilverlightHelper">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
<extendedProtectionPolicy policyEnforcement="Never" />
</httpTransport>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:50072/API/WCF/Silverlight/SilverlightHelper.svc"
binding="customBinding" bindingConfiguration="CustomBinding_ISilverlightHelper"
contract="API.WCF.Silverlight.ISilverlightHelper" name="CustomBinding_ISilverlightHelper" />
</client>
</system.serviceModel>
</configuration>

我不知道如何创建等效的客户端配置代码。目前我有:

CustomBinding customBinding = new CustomBinding();
// I see I need to do something with customBinding but the properties don't seem
// logical
// I have used BasicHttpBinding, but it just returns with "Not Found" (the service does resolve to a valid URL)
BasicHttpBinding basicHttpBinding = new BasicHttpBinding() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:50072/API/WCF/Silverlight/SilverlightHelper.svc");
ISilverlightHelper silverlightHelper= new ChannelFactory<ISilverlightHelper>(basicHttpBinding, endpointAddress).CreateChannel();
AsyncCallback asyncCallback = delegate(IAsyncResult result)
{
ISilverlightHelper asyncSilverlightHelper = (ISilverlightHelper)result.AsyncState;
string[] files=asyncSilverlightHelper.EndGetPlugInXapNames(result).ToArray();
};
silverlightHelper.BeginGetPlugInXapNames(asyncCallback, silverlightHelper);

任何线索将不胜感激。我整个上午都在谷歌搜索/Binging/Overflowing 上度过,但还没有遇到这种情况。或者我可能错得太远了......

最佳答案

已排序。

我创建了 BinaryMessageEncodingBindingElement 和 HttpTransportBindingElements,将它们添加到 CustomBinding,一切正常。

这是我的注释代码:

// create the binding elements
BinaryMessageEncodingBindingElement binaryMessageEncoding = new BinaryMessageEncodingBindingElement();
HttpTransportBindingElement httpTransport = new HttpTransportBindingElement() { MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue };

// add the binding elements into a Custom Binding
CustomBinding customBinding = new CustomBinding(binaryMessageEncoding,httpTransport);

// create the Endpoint URL (I'll use a configured URL later - all web services will then move as one)
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:50072/API/WCF/Silverlight/SilverlightHelper.svc");

// create an interface for the WCF service
ISilverlightHelper silverlightHelper= new ChannelFactory<ISilverlightHelper>(customBinding, endpointAddress).CreateChannel();

// set-up the asynchronous callback
AsyncCallback asyncCallback = delegate(IAsyncResult result)
{
ISilverlightHelper asyncSilverlightHelper = (ISilverlightHelper)result.AsyncState;
string[] files=asyncSilverlightHelper.EndGetPlugInXapNames(result).ToArray();
};

// execute the call
silverlightHelper.BeginGetPlugInXapNames(asyncCallback, silverlightHelper);

关于wcf - [Silverlight] WCF 客户端的编程配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1410757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com