2016-06-14 9 views
1

私の問題は、私がこのWebservice EServiceを持っていて、デバッグプロジェクトで本当にうまく動作しますが、WinFormプロジェクトに実装して、サーバ。クライアントを評価するときにこのエラーが発生しますか?WCF:サーバー上でWebサービスを稼働させようとする

An unhandled exception of type 'System.InvalidOperationException' 
occurred in System.ServiceModel.dll 

Could not find default endpoint element that references contract '{0}' in the ServiceModel 
client configuration section. This might be because no configuration file was found for your application, 
or because no endpoint element matching this contract could be found in the client element. 

App.configを

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicHttpBinding_IEService" /> 
    </basicHttpBinding> 
</bindings> 
<client> 
    <endpoint address="http://Domane.dk/EService.svc" binding="basicHttpBinding" 
     bindingConfiguration="BasicHttpBinding_IEService" contract="IEService" 
     name="BasicHttpBinding_IEService" /> 
</client> 

のWeb.config

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<protocolMapping> 
    <add binding="basicHttpBinding" scheme="http" /> 
    <add binding="basicHttpsBinding" scheme="https" /> 
</protocolMapping> 
<bindings> 
    <basicHttpBinding> 
    <binding name="" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

イム

それを呼び出す方法
using (var test = new EServiceAPI.EServiceClient()) 
     { 
      test.OpdaterLeastDatoWinPLC(connstr); 
     } 

私は失敗する理由はありません。そんな新人になってすみません。そして、はい、私は今、解決策を見つけることを試みる2日間インターネットを収穫しました。

答えて

1

DLL内のWebサービスを使用しているとき、私は同じ問題がありました。 これを試してみてください:

using (var test = CreateWebServiceInstance("http://url.to.mywebservice.com")) 
    { 
     test.OpdaterLeastDatoWinPLC(connstr); 
    } 

は、上記のWebサービスへの正しいURLを入力して以下のコードを使用してクライアントを作成します。 EServiceClientクラスが作成されるように、Webサービスをプロジェクトに追加する必要があります。

internal static EServiceAPI.EServiceClient CreateWebServiceInstance(string url) { 
     BasicHttpBinding binding = new BasicHttpBinding(); 
     binding.SendTimeout = TimeSpan.FromMinutes(10); 
     binding.OpenTimeout = TimeSpan.FromMinutes(1); 
     binding.CloseTimeout = TimeSpan.FromMinutes(1); 
     binding.ReceiveTimeout = TimeSpan.FromMinutes(20); 
     binding.AllowCookies = false; 
     binding.BypassProxyOnLocal = false; 
     binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; 
     binding.MessageEncoding = WSMessageEncoding.Text; 
     binding.TextEncoding = Encoding.UTF8; 
     binding.TransferMode = TransferMode.Buffered; 
     binding.UseDefaultWebProxy = true; 
     binding.MaxReceivedMessageSize = 5242880; 
     return new EServiceAPI.EServiceClient(binding, new EndpointAddress(url)); 
    } 

これが機能する場合は、上記の設定を必要に応じて変更することができます。

+0

どのように、なぜか、私は知らないが、これは動作します。どうもありがとうございました – Christian

0

私はこれが<endpoint address="http://Domane.dk/EService.svc"と関係があると思います。サーバー上で使用する場合、相対パスにする必要があります。

同様: <endpoint address="./EService.svc"

関連する問題