[英]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.