简体   繁体   English

将json参数传递给WCF函数,并给出错误消息“服务器在处理请求时遇到错误。 请参阅服务器日志以获取更多详细信息”

[英]passing json parameters to WCF function giving error “The server encountered an error processing the request. See server logs for more details”

i have a WCF service which takes in one string parameter. 我有一个WCF服务,它接受一个字符串参数。 When i attempt to give call to it i get an error "The server encountered an error processing the request. See server logs for more details" I have reproduced this issue by passing json request from fiddler too.. just to be sure that my jQuery $.ajax() does not have the issue. 当我尝试调用它时,出现错误“服务器在处理请求时遇到错误。请参阅服务器日志以获取更多详细信息”。我也通过传递来自提琴手的json请求来重现此问题。.只是为了确保我的jQuery $ .ajax()没有问题。

Here is my ServiceContract, WCF class and configuration - 这是我的ServiceContract,WCF类和配置-

Service Contract - 服务合同 -

[ServiceContract]
public interface iAgentDesktop
{
    [OperationContract]
    string Transfer(string extensionNumber);
    [OperationContract]
    string Conference(string extensionNumber);
}

WCF Service WCF服务

public class AgentDesktopMediator : iAgentDesktop
{
    string iAgentDesktop.Conference(string extensionNumber)
    {
            //do something
            return "";
    }
    string iAgentDesktop.Conference(string extensionNumber)
    {
        do something
        return "";
    }
}

configuration file - 配置文件-

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WCFListener.AgentDesktopMediator">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8070/"/>
          </baseAddresses>
        </host>
        <endpoint address="AgentDesktopMediator" binding="basicHttpBinding" contract="WCFListener.iAgentDesktop"></endpoint>
        <endpoint address="jAgentDesktopMediator" binding="webHttpBinding" contract="WCFListener.iAgentDesktop" behaviorConfiguration="web"></endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp defaultOutgoingResponseFormat="Json"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>

You will need to find actual error in the trace file. 您将需要在跟踪文件中找到实际的错误。 To create the trace file, first create a folder in your c drive called logs and put the following section in your wcf config file 要创建跟踪文件,请首先在c驱动器中创建一个名为logs的文件夹,并将以下部分放入wcf配置文件中

<system.diagnostics>
<sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <listeners>
      <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Traces.svclog" />
    </listeners>
  </source>
</sources>
</system.diagnostics>

Now whenever you call your service it will pull all the diagnostic information in the trace file which you can double click and open in MS Trace viewer. 现在,无论何时调用服务,它都会将所有诊断信息拉到跟踪文件中,您可以双击并在MS Trace查看器中打开它。

OK, my question was by itself incomplete.. i conclude this after the issue is resolved now.. 好的,我的问题本身是不完整的。.我现在解决问题后得出结论。

the issue was that in my content type i did not put a semi-colon between contentType and charset.. 问题是,在我的内容类型中,我没有在contentType和charset之间放置分号。

this is what i provided in my $.ajax() - 这就是我在$ .ajax()中提供的内容-

Content-Type: application/json charset=utf-8

it had to be - 它必须是-

Content-Type: application/json; charset=utf-8

And, i never bothered to see the header while attempting to hit the service from fiddler too.. i was concentrating only on the format of data that i was supplying 而且,在尝试从提琴手那里访问服务时,我也从来没有打扰过标题。.我只专注于提供的数据格式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IIS 8中的WCF和EntityFramework错误服务器在处理请求时遇到错误 - WCF and EntityFramework error in IIS 8 The server encountered an error processing the request SWAGGER错误。 服务器在处理请求时遇到错误 - SWAGGER Error. The server encountered an error processing the request 服务器在处理请求时遇到错误-服务不存在 - The server encountered an error processing the request - the service does not exist 无法获得REST请求响应的实际错误。 Fiddler向我展示了更多错误细节。 在.NET中,我得到的是500 - 内部服务器错误 - Can't get actual error in response for REST request. Fiddler shows me more error details. In .NET all I get is 500 - Internal Server Error C#WCF“ System.Net.WebException:远程服务器返回错误:(400)错误的请求。” - C# WCF “System.Net.WebException: The remote server returned an error: (400) Bad Request.” 付款错误:PayPal错误:请求无效。查看详细信息。 (VALIDATION_ERROR)Paypal - Payment error: PayPal error: Invalid request. See details. (VALIDATION_ERROR) Paypal 远程服务器返回错误:(400)错误请求。 - The remote server returned an error: (400) Bad Request. 获取错误“远程服务器返回错误:(400)错误请求。”在线WebResponse response = request.GetResponse(); - Getting error “ The remote server returned an error: (400) Bad Request.” on line WebResponse response = request.GetResponse(); 尝试使用wcf上传50kb大小的图像时,显示错误“远程服务器返回了意外的响应:(400)错误的请求。” - While trying to upload image of 50kb size using wcf , shows error 'The remote server returned an unexpected response: (400) Bad Request.' 处理您的请求时发生错误。 MVC 4 - An error occurred while processing your request. MVC 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM