簡體   English   中英

在WPF應用程序上部署WCF服務時出錯

[英]Error in deploying WCF service on WPF application

我正在WCF應用程序上,啟動簡單的HelloWorld服務。 我已經開發了簡單的WPF應用程序來托管服務,即啟動和停止服務

當我嘗試在WCFTestClient上使用URL“ http:// localhost:8087 / MyServices / HelloWorldService ”測試此服務時,出現以下錯誤

Error: Cannot obtain Metadata from http://localhost:8087/MyServices/HelloWorldService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://localhost:8087/CreditUnionServices/HelloWorldService    Metadata contains a reference that cannot be resolved: 'http://localhost:8087/CreditUnionServices/HelloWorldService'.    <?xml version="1.0" encoding="utf-16"?><Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Sender</Value><Subcode><Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</Value></Subcode></Code><Reason><Text xml:lang="en-GB">The message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</Text></Reason></Fault>HTTP GET Error    URI: http://localhost:8087/CreditUnionServices/HelloWorldService    There was an error downloading 'http://localhost:8087/CreditUnionServices/HelloWorldService'.    The request failed with HTTP status 400: Bad Request.

app.config

 <system.serviceModel>
<services>
  <service name="App.Services.Managers.HelloWorldManager">
    <endpoint address="HelloWorldService"
              binding="wsHttpBinding"
              contract="App.Services.Contracts.IHelloWorldService">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8087/MyService"/>
      </baseAddresses>
    </host>
  </service>
</services>

C#類打開和關閉服務

public class ServicesHostManager
{
    ServiceHost _helloWorldServicesHost = new ServiceHost(typeof(HelloWorldManager));

    public void ProcessHelloWorldService(string _process)
    {
        if(!string.IsNullOrEmpty(_process))
        {
            try
            {
                if (_process.Equals("open_service"))
                {
                    _helloWorldServicesHost.Open();
                }
                else if (_process.Equals("close_service"))
                {
                    _helloWorldServicesHost.Close();
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.ToString());
            }
        }
    }

先前的評論者處在正確的軌道上,您需要聲明一個mex端點。 mex是提供元數據的工具。

嘗試以下配置:

<system.serviceModel>
<services>
  <service name="App.Services.Managers.HelloWorldManager" behaviorConfiguration="SimpleWcfServiceBehavior">
    <endpoint address="HelloWorldService"
              binding="wsHttpBinding"
              contract="App.Services.Contracts.IHelloWorldService">
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8087/MyService"/>
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="SimpleWcfServiceBehavior">
      <!-- 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>
</system.serviceModel>

我有更新代碼,現在正在工作,

 <system.serviceModel>
<services>
  <service name="App.Services.Managers.HelloWorldManager" behaviorConfiguration="DefaultServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8087/MyService"/>
      </baseAddresses>
    </host>
    <endpoint address="HelloWorldService" binding="wsHttpBinding" contract="App.Services.Contracts.IHelloWorldService"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="DefaultServiceBehavior">
      <serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM