繁体   English   中英

如何从使用WCF绑定的app.config转到如何以正确的方式将其转换为以编程方式进行绑定

[英]how to go from using app.config of WCF binding and convert it to bind programmatically in correct manner

我有以下绑定,在创建客户端时可以正常工作。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="Assets_AssetsPort" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
                <binding name="AssetsPortBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://osi-tm/services/Assets" binding="basicHttpBinding"
                bindingConfiguration="Assets_AssetsPort" contract="InterplayWS.AssetsPortType"
                name="AssetsPort" />
        </client>
    </system.serviceModel>
</configuration>

但是现在我需要在没有任何配置文件的情况下进行配置。 因此,我尝试执行以下操作:

    BasicHttpBinding basicBinding = new BasicHttpBinding()
    {
        MaxReceivedMessageSize = 2147483647,
        MaxBufferPoolSize = 2147483647
    };
    basicBinding.MessageEncoding = WSMessageEncoding.Mtom;


    var endpoint = new EndpointAddress(new Uri(String.Format("http://{0}/services/Assets?wsdl", Connection.InterplayHost)));

    var client = new AssetClient(basicBinding, endpoint);

当我运行它时,我得到一个错误

<Exception>
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Unrecognized message version.</Message>
<StackTrace>
at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders)
at System.ServiceModel.Channels.MtomMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp; requestException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
at DDMEService.InterplayReference.AssetsPortType.GetChildren(GetChildrenRequest request)
at DDMEService.InterplayReference.AssetsPortTypeClient.DDMEService.InterplayReference.AssetsPortType.GetChildren(GetChildrenRequest request)
at DDMEService.InterplayReference.AssetsPortTypeClient.GetChildren(UserCredentialsType UserCredentials, GetChildrenType GetChildren1)
at DDMEService.Classes.AvidCommand.PopulateGenericAssets(String UNCHostname, String UNCDirectoryPath)
at DDMEService.Classes.CommandManager.PrepareAvidList(String HostName, String DirectoryPath, Boolean SearchSubdirectory, Boolean RenameToDirectory, String FileFilter, String ExtensionFilter, String InterplayHost, String InterplayWorkgroup, String Catalog, String LocatorSequenceStartWords, String LocatorSequenceEndWords, String Username, String Password)
at DDMEService.Classes.CommandManager.Execute()
at DDMEService.ClientHandler.ProcessCommand(String ClientIP, String Command)
at DDMEService.ClientHandler.Process(Object O)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: Unrecognized message version.</ExceptionString>
</Exception>

无法使用肥皂的要求

--uuid:4475db34-2787-4220-b800-15c91678a4be+id=2
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:UserCredentials xmlns:h="http://avid.com/interplay/ws/assets/types" xmlns="http://avid.com/interplay/ws/assets/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Username>Administrator</Username><Password>avid</Password></h:UserCredentials><ActivityId CorrelationId="f29e64f8-1568-4683-b196-d53bd97a2cec" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">13063b98-becc-416a-89ec-23a23498ed21</ActivityId></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetChildren xmlns="http://avid.com/interplay/ws/assets/types"><InterplayURI>interplay://A51WG6/Catalogs/000</InterplayURI></GetChildren></s:Body></s:Envelope>
--uuid:4475db34-2787-4220-b800-15c91678a4be+id=2--

工作肥皂要求

--uuid:f1481ad5-def1-42bf-a3ca-f9cff5eb856b+id=2
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:UserCredentials xmlns:h="http://avid.com/interplay/ws/assets/types" xmlns="http://avid.com/interplay/ws/assets/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Username>Administrator</Username><Password>avid</Password></h:UserCredentials></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetChildren xmlns="http://avid.com/interplay/ws/assets/types"><InterplayURI>interplay://WG5C/Catalogs/Sundance</InterplayURI></GetChildren></s:Body></s:Envelope>
--uuid:f1481ad5-def1-42bf-a3ca-f9cff5eb856b+id=2--

我如何正确地形成表格以使其与我的服务相抵触?

您为什么要创建元素然后按下mtom? 您已经有一个文本编码器,因此mtom将是第二个编码器。 改用这个:

basicBinding.messageEncoding = WSMessageEncoding.Mtom

我必须从http:// {0} / services / Assets?wsdl中删除?wsdl

要在代码中创建等效绑定,您只需要将BasicHttpBinding实例上的属性设置为配置文件中指定的值即可。

通过快速浏览代码,您似乎可以删除创建MtomMessageEncodingBindingElement实例的代码,并将basicBinding的MessageEncoding属性设置为Mtom。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM