私はこのリンクをたどっています:
http://aspdotnetcodebook.blogspot.in/2012/02/calling-cross-domain-wcf-service-using.html
クロスドメインを実装する場合、consol アプリケーションでは機能しますが、svc web wcf サービス アプリケーションでは機能しません。
私は何をすべきか ?
編集:
[ServiceContract]
public interface IOrderService
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/", ResponseFormat = WebMessageFormat.Json)]
string ProcessOrder();
}
namespace WFS.Services
{
[ServiceBehavior]
public class OrderService : IOrderService
{
[OperationBehavior]
public string ProcessOrder()
{
Order order = new Order
{
ID = 1,
OrderDate = DateTime.Now,
Name = "Laptop"
};
DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(Order));
MemoryStream stream = new MemoryStream();
json.WriteObject(stream, order);
return Encoding.UTF8.GetString(stream.ToArray());
}
}
}
および構成コード:
configuration>
<system.serviceModel>
<services>
<service name="WFS.Services.OrderService" behaviorConfiguration="serviceBehave">
<endpoint address=""
bindingConfiguration="crossDomain"
behaviorConfiguration="enableScriptBehaviour"
binding="webHttpBinding"
contract="WFS.Services.IOrderService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:4916/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehave">
<serviceMetadata httpGetEnabled="true" httpGetUrl="mex"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="enableScriptBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
ここにjson getがあります:
$.getJSON("http://localhost:4916/Order.svc?ProcessOrder?callback?", null, function (data) {
alert(data);
});
それは私にパーサーエラー200成功を与えます