自托管WCF服务的路由

时间:2013-08-16 15:43:22

标签: wcf asp.net-routing

我有一个自托管的WCF服务,可以侦听端口80(第三方设备不支持在其他端口上发送)。我还有两个网站和三个Web API基础服务,这些服务也在端口80上运行良好。所有这些服务/站点都使用不同的FQDN(test-svc1.example.com,test-svc2.example.com,test-site1.example.com等)运行。请务必注意,所有子域都指向服务器上的相同IP地址。所有这一切都很有效,直到我尝试安装托管我的WCF服务的服务。当我尝试导航到我的两个站点之一时安装该服务后,我会得到一个页面,其中包含以下信息:

.....

您已创建了一项服务。

要测试此服务,您需要创建一个客户端并使用它来调用该服务。您可以使用命令行中的svcutil.exe工具执行此操作,语法如下:

.....

如果我停止基于WCF的服务,那么我的网站工作正常。

以下是用于托管WCF服务的代码。     公共类MyService     {         private const string MyServiceName =“MyService”;         私人ServiceHost _selfHost;

    public void Start()
    {
        this._selfHost = new ServiceHost(typeof(MyWebService), new Uri(wcf.exampe.com));

        try
        {
            BasicHttpBinding binding = new BasicHttpBinding();
            int tempValue = 0;
            this._selfHost.AddServiceEndpoint(typeof(IMyServiceContract), binding, MyServiceName);

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            this._selfHost.Description.Behaviors.Add(smb);

            this._selfHost.Open();

        }
        catch ( CommunicationException ce )
        {
            this._selfHost.Abort();
        }
    }

    public void Stop()
    {
        // Close the ServiceHostBase to shutdown the service.
        this._selfHost.Close();

    }
}

此代码由Windows服务包装程序调用。我需要的是这个服务能够在端口80上运行,但只监听与wcf.example.com相关的数据包。

---------活动查看者信息

我已在事件查看器中启用调试和跟踪,以查看是否可以帮助我隔离问题。以下是其中的一些项目。

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
        <Provider Name="Microsoft-Windows-Application Server-Applications" Guid="{c651f5f6-1c0d-492e-8ae1-b4efd7c9d503}" /> 
        <EventID>57396</EventID> 
        <Version>0</Version> 
        <Level>3</Level> 
        <Task>0</Task> 
        <Opcode>0</Opcode> 
        <Keywords>0x2000000000010000</Keywords> 
        <TimeCreated SystemTime="2013-08-16T20:52:13.956945800Z" /> 
        <EventRecordID>99</EventRecordID> 
        <Correlation ActivityID="{1E2ADE87-F4FC-4B42-8711-DD49B2F0DB6B}" /> 
        <Execution ProcessID="1716" ThreadID="4828" ProcessorID="0" KernelTime="0" UserTime="3" /> 
        <Channel>Microsoft-Windows-Application Server-Applications/Analytic</Channel> 
        <Computer>MyComputer</Computer> 
        <Security UserID="S-1-5-18" /> 
    </System>
    <EventData>
        <Data Name="data1">System.ServiceModel 4.0.0.0</Data> 
        <Data Name="data2">System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---> System.Xml.XmlException: The body of the message cannot be read because it is empty. --- End of inner exception stack trace ---</Data> 
        <Data Name="SerializedException">
            <Exception>
                <ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
                </ExceptionType>
                <Message>There is a problem with the XML that was received from the network. See inner exception for more details.
                </Message>
                <StackTrace> at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth) at System.Runtime.Diagnostics.EtwDiagnosticTrace.ExceptionToTraceString(Exception exception, Int32 maxTraceStringLength) at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetSerializedPayload(Object source, TraceRecord traceRecord, Exception exception, Boolean getServiceReference) at System.Runtime.TraceCore.ThrowingException(EtwDiagnosticTrace trace, String param0, String param1, Exception exception) at System.Runtime.ExceptionTrace.TraceException[TException](TException exception, String eventSource) at System.Runtime.ExceptionTrace.AsError(Exception exception) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result) at System.Runtime.AsyncResult.SyncContinue(IAsyncResult result) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor acceptor, Action dequeuedCallback, HttpPipeline pipeline, AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync() at System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state) at System.ServiceModel.Channels.SharedHttpTransportManager.EnqueueContext(IAsyncResult listenerContextResult) at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult listenerContextResult) at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.ListenerAsyncResult.IOCompleted(ListenerAsyncResult asyncResult, UInt32 errorCode, UInt32 numBytes) at System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
                </StackTrace>
                <ExceptionString>System.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details. ---&amp;gt; System.Xml.XmlException: The body of the message cannot be read because it is empty. --- End of inner exception stack trace ---
                </ExceptionString>
                <InnerException>
                    <Exception>
                        <ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
                        </ExceptionType>
                        <Message>The body of the message cannot be read because it is empty.
                        </Message>
                        <StackTrace> at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth) at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetInnerException(Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth) at System.Runtime.Diagnostics.EtwDiagnosticTrace.WriteExceptionToTraceString(XmlTextWriter xml, Exception exception, Int32 remainingLength, Int32 remainingAllowedRecursionDepth) at System.Runtime.Diagnostics.EtwDiagnosticTrace.ExceptionToTraceString(Exception exception, Int32 maxTraceStringLength) at System.Runtime.Diagnostics.EtwDiagnosticTrace.GetSerializedPayload(Object source, TraceRecord traceRecord, Exception exception, Boolean getServiceReference) at System.Runtime.TraceCore.ThrowingException(EtwDiagnosticTrace trace, String param0, String param1, Exception exception) at System.Runtime.ExceptionTrace.TraceException[TException](TException exception, String eventSource) at System.Runtime.ExceptionTrace.AsError(Exception exception) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result) at System.Runtime.AsyncResult.SyncContinue(IAsyncResult result) at System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor acceptor, Action dequeuedCallback, HttpPipeline pipeline, AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state) at System.ServiceModel.Channels.HttpChannelListener`1.HttpContextReceivedAsyncResult`1.ProcessHttpContextAsync() at System.ServiceModel.Channels.HttpChannelListener`1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state) at System.ServiceModel.Channels.SharedHttpTransportManager.EnqueueContext(IAsyncResult listenerContextResult) at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContextCore(IAsyncResult listenerContextResult) at System.ServiceModel.Channels.SharedHttpTransportManager.OnGetContext(IAsyncResult result) at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.ListenerAsyncResult.IOCompleted(ListenerAsyncResult asyncResult, UInt32 errorCode, UInt32 numBytes) at System.Net.ListenerAsyncResult.WaitCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
                        </StackTrace>
                        <ExceptionString>System.Xml.XmlException: The body of the message cannot be read because it is empty.
                        </ExceptionString>
                    </Exception>
                </InnerException>
            </Exception>
        </Data> 
        <Data Name="AppDomain">MyService.exe</Data> 
    </EventData>
</Event>

-----------------结束错误

传输已向“http://x.x.x.8/data/MyService”发送了一条消息。

处理异常。异常详细信息:System.ServiceModel.ProtocolException:从网络收到的XML存在问题。有关详细信息,请参阅内部异常---&GT; System.Xml.XmlException:无法读取消息正文,因为它是空的。    ---内部异常堆栈跟踪结束---    在System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult结果)    在System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult结果)    在System.Runtime.AsyncResult.SyncContinue(IAsyncResult结果)    在System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult..ctor(ReplyChannelAcceptor acceptor,Action dequeuedCallback,HttpPipeline pipeline,AsyncCallback callback,Object state)    在System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor,Action dequeuedCallback,AsyncCallback callback,Object state)    在System.ServiceModel.Channels.HttpChannelListener 1.HttpContextReceivedAsyncResult 1.ProcessHttpContextAsync()

HttpGetContext start。

---------活动查看者信息

如前所述,在Visual Studio下运行时,所有这些都可以在我的测试框中正常工作,但在我的生产盒作为服务运行时不起作用。

此致

Richard O

0 个答案:

没有答案