0

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

<?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--

我怎样才能正确地形成它以使其对我的服务起作用?

4

3 回答 3

2

为什么要创建元素然后推送 mtom?你已经有一个文本编码器,所以 mtom 将是第二个编码器。改用这个:

basicBinding.messageEncoding = WSMessageEncoding.Mtom
于 2012-04-18T15:46:53.150 回答
0

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

于 2012-04-19T15:51:43.163 回答
-1

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

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

于 2012-04-18T11:55:39.633 回答