WCF webservice - 无法在生产中使用它

时间:2011-11-22 18:33:55

标签: wcf web-services authentication

我有一个网络服务,它提供了一个要发送的邮件列表。它在localhost上工作正常,但不能在生产中工作。

我的网络服务应该没有任何限制。它根本不安全,但坦率地说,在这一点上,我根本不关心它。

我收到了这些错误:

我整天都在看着它,我担心我不记得我为哪个错误做了哪些修改。

我得到的最新错误是......一个蹩脚的超时,没有任何感觉。但是,有趣的是:我已将每个超时配置为10小时,并在几秒钟后得到超时。

我的web.config(服务器)有这个(实际上,它有4个web服务,但我只留下了我现在尝试使用的那个):

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="wsHttpBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferPoolSize="20000000" useDefaultWebProxy="true">
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                </security>
            </binding>
            <binding name="NoSecurityBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferPoolSize="20000000" useDefaultWebProxy="true">
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="CentresInteretBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
                <serviceCredentials>
                    <windowsAuthentication allowAnonymousLogons="true" />
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="CentresInteretBehavior" name="CentresInteret">
            <endpoint address="" binding="wsHttpBinding" contract="ICentresInteret" bindingConfiguration="NoSecurityBinding">
                <identity>
                    <dns value="localhost" />
                    <userPrincipalName value=".\ASPNET" />
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>

我的app.config(客户端)有这个(同样的事情:多个WS,只有一个被调用):

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_ICentresInteret" closeTimeout="10:00:00"
                openTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="20000000" maxReceivedMessageSize="20000000"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="200000000"
                    maxArrayLength="200000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="10:00:00" enabled="false" />
                <security mode="None">
                    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="false"
                        algorithmSuite="Default" establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://www.ourserver.com/WebServices/CentresInteret.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICentresInteret"
            contract="CentresInteretService.ICentresInteret" name="WSHttpBinding_ICentresInteret">
            <identity>
                <dns value="localhost" />
                <userPrincipalName value=".\ASPNET" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

服务器跟踪让我知道这一点,在红线上几秒钟后(大约10-15)(请问我是否需要另一条线路):

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
        <EventID>131076</EventID>
        <Type>3</Type>
        <SubType Name="Error">0</SubType>
        <Level>2</Level>
        <TimeCreated SystemTime="2011-11-28T17:46:26.6525694Z" />
        <Source Name="System.ServiceModel" />
        <Correlation ActivityID="{f624ff35-a8ae-4636-bd46-2138207af7a1}" />
        <Execution ProcessName="w3wp" ProcessID="20424" ThreadID="7" />
        <Channel />
        <Computer>SRV-WEB-01</Computer>
    </System>
    <ApplicationData>
        <TraceData>
            <DataItem>
                <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
                    <TraceIdentifier>http://msdn.microsoft.com/fr-FR/library/System.ServiceModel.Diagnostics.TraceHandledException.aspx</TraceIdentifier>
                    <Description>Traitement d’une exception.</Description>
                    <AppDomain>/LM/W3SVC/4/ROOT-1-129669759749681489</AppDomain>
                    <Exception>
                        <ExceptionType>System.Net.WebException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
                        <Message>Le délai d'attente de l'opération a expiré.</Message>
                        <StackTrace>
                            à System.Net.HttpWebRequest.GetResponse()
                            à CentresInteret.RecupererContenuMail(Int32 contact_id, Int32 frequence_id, Int32 organisme_id) dans D:\...\App_Code\WebServices\CentresInteret.vb:ligne 181
                            à CentresInteret.GetEmails(Boolean PrendreEnCompteFrequence) dans D:\...\App_Code\WebServices\CentresInteret.vb:ligne 87
                            à SyncInvokeGetEmails(Object , Object[] , Object[] )
                            à System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)
                            à System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                        </StackTrace>
                        <ExceptionString>
                            System.Net.WebException: Le délai d'attente de l'opération a expiré.
                            à System.Net.HttpWebRequest.GetResponse()
                            à CentresInteret.RecupererContenuMail(Int32 contact_id, Int32 frequence_id, Int32 organisme_id) dans D:\...\App_Code\WebServices\CentresInteret.vb:ligne 181
                            à CentresInteret.GetEmails(Boolean PrendreEnCompteFrequence) dans D:\...\App_Code\WebServices\CentresInteret.vb:ligne 87
                            à SyncInvokeGetEmails(Object , Object[] , Object[] )
                            à System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp;amp; outputs)
                            à System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;amp; rpc)
                            à System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                        </ExceptionString>
                    </Exception>
                </TraceRecord>
            </DataItem>
        </TraceData>
    </ApplicationData>
</E2ETraceEvent>

请相当请,请知道。我全都不在了。我有点疯了。

谢谢!

修改:已解决!在第181行的CentresInteret.vb中,有:

    Dim req As HttpWebRequest = WebRequest.Create(pageModele)
    req.Timeout = 10000
    Dim resp As HttpWebResponse = req.GetResponse() ' throws the error

我在超时时添加了零,现在它可以工作了!显然,10秒的超时时间还不够......

1 个答案:

答案 0 :(得分:2)

如果此跟踪来自您的服务器(而不是客户端),那么我很好奇这个错误:

  

CentresInteret.RecupererContenuMail(Int32 contact_id,Int32 frequence_id,Int32 organisme_id)dans D:... \ App_Code \ WebServices \ CentresInteret.vb:ligne 181

看起来CentresInteret.RecupererContenuMail()方法是代码中的方法之一?如果是这样,文件CentresInteret.vb的第181行是做什么的?在查询某些内容时,它看起来可能会超时?也许它在那条线上做DB调用或者调用另一个Web服务?

这部分例外:

  

System.Net.WebException:Ledélaid'emptede l'opérationoexpiré。         àSystem.Net.HttpWebRequest.GetResponse()

使您的Web服务代码看起来像是向另一个服务发出另一个Web请求,并且可能会超时。如果oyu正在查询另一个服务(如Exchange或某些POP3邮件服务器),那么它的超时可能是10-15秒,并且该超时冒泡到您的WCF客户端(尽管如the_ajp所述,它应该包含在{{1}中在客户端。)