Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF:System.ServiceModel.Diagnostics.TraceUtibility的类型初始值设定项引发异常_C#_Wcf_Nhibernate - Fatal编程技术网

C# WCF:System.ServiceModel.Diagnostics.TraceUtibility的类型初始值设定项引发异常

C# WCF:System.ServiceModel.Diagnostics.TraceUtibility的类型初始值设定项引发异常,c#,wcf,nhibernate,C#,Wcf,Nhibernate,我想测试我的WCF服务,但出现以下错误: System.TypeInitializationException:'的类型初始值设定项 “System.ServiceModel.Diagnostics.TraceUtibility”引发异常。 我将我的WCF服务引用到我的测试类(WSTester) 这是内在的例外: 我是WCF的新手。我认为我的App.config文件是错误的,但我不知道如何实现它。我在浏览器里试过了。它起作用了,但在控制台应用程序中不起作用 这是我的WSTester中的测试程序:

我想测试我的WCF服务,但出现以下错误:

System.TypeInitializationException:'的类型初始值设定项
“System.ServiceModel.Diagnostics.TraceUtibility”引发异常。

我将我的WCF服务引用到我的测试类(WSTester)

这是内在的例外:

我是WCF的新手。我认为我的App.config文件是错误的,但我不知道如何实现它。我在浏览器里试过了。它起作用了,但在控制台应用程序中不起作用

这是我的WSTester中的测试程序:

public class Program
{
    static void Main(string[] args)
    {
        Service1Client client = new Service1Client();
        Customer c = new Customer();
        c.Name = "dsfsfsdf";
        c.SurName="asdass";
        c.Age = 12;
        client.CreateCustomer(c);
    }
}
这是我的App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <compile debug="true">
  </compile>
  <system.serviceModel>
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="99" />
    <bindings>
      <webHttpBinding>
        <binding name="webHttpBindingWithJsonP" />
      </webHttpBinding>
   </bindings>
    <client>
      <endpoint address="http://192.168.0.xx:7767/Service1.svc"
        binding="webHttpBinding"
        contract="WorkWS.IService1" behaviorConfiguration="webhttp" />
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webhttp">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

编译器正在抱怨错误

  <compile debug="true">
  </compile>

元素,该元素无效。把它拿走


顺便问一下,当Service1.svc?wsdl写入URL时,它从何而来

    <wsdl:service name="Service1"/>
    </wsdl:definitions>


我认为这是另一个问题。:-。你的app.config中的合同不应该是
WebService.IService1
而不是
WorkWS.IService1
好吧,很公平。您是否查看了服务器(IIS?)日志以了解服务器上实际请求的详细信息?嗯,您需要在IIS中打开WCF应用程序的IIS日志,否则您会发现各种难以诊断的问题。搜索客户端发布到的URL,我认为这是
http://192.168.0.xx:7767/Service1.svc
。或者只需“Service1.svc”,然后查看URL在日志中是否正确。如果可以,将日志条目张贴在此处。如果键入
http://192.168.0.xx:7767/Service1.svc?wsdl
在浏览器地址栏中?
    [WebInvoke(Method = "POST",
    UriTemplate = "CreateCustomer",
    BodyStyle = WebMessageBodyStyle.WrappedRequest,
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]
    public Customer CreateCustomer(Customer customer)
    {
        if (customer == null)
        {
            throw new ArgumentNullException("FAIL");
        }
        CustomerManager cm = new CustomerManager();
        cm.CreateCustomer(customer);

        return customer;
    }
  <compile debug="true">
  </compile>
    <wsdl:service name="Service1"/>
    </wsdl:definitions>