Tôi ghét thiết lập WCF với điểm cuối, hành vi, v.v. Tôi tin rằng tất cả những điều này sẽ được thực hiện tự động. Tất cả những gì tôi muốn làm là trả về kết quả JSON từ dịch vụ WCF của tôi. Dưới đây là cấu hình của tôi:Địa chỉ WCF Địa ngục?
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="default"/>
</webHttpBinding>
</bindings>
<services>
<service name="HighOnCodingWebApps.ZombieService"
behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="default"
contract="HighOnCodingWebApps.IZombieService"
behaviorConfiguration="webScriptEnablingBehavior"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webScriptEnablingBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"/>
Và tôi có thực hiện dịch vụ sau:
public class ZombieService : IZombieService
{
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "KnownZombies")]
public Zombie GetZombie()
{
return new Zombie() { Name = "Mohammad Azam"};
}
}
public class Zombie
{
public string Name { get; set; }
}
Khi tôi ghé thăm http://localhost:22059/ZombieService/KnownZombies
nói được thông báo sau:
thiết bị đầu cuối sử dụng 'UriTemplate' không thể được sử dụng với 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
Nếu tôi loại bỏ các WebScriptEnablingBehavior từ web.config tôi nhận được lỗi sau:
The message with To 'http://localhost:22059/ZombieService.svc/KnownZombies' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
UPDATE 1:
tôi cập nhật cấu hình như thế này:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="default"/>
</webHttpBinding>
</bindings>
<services>
<service name="HighOnCodingWebApps.ZombieService"
behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="http://localhost:22059/ZombieService.svc" binding="webHttpBinding"
bindingConfiguration="default"
contract="HighOnCodingWebApps.IZombieService"
/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="SomeBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Bây giờ khi Tôi truy cập http://localhost:22059/ZombieService.svc/KnownZombies
Tôi nhận được thông báo sau trong trình duyệt:
The message with To 'http://localhost:22059/ZombieService.svc/KnownZombies' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.
Không kéo lên bất cứ điều gì? Bạn có thể thử đăng nội dung nào đó hữu ích và có thể bao gồm câu hỏi không? –
Kiểm tra WCF 4.0 - nó đã khắc phục ** rất nhiều ** đau đầu cấu hình! Đọc [Giới thiệu của nhà phát triển đến WCF 4] (http://msdn.microsoft.com/en-us/library/ee354381.aspx) để biết thêm chi tiết. –
cập nhật câu hỏi – azamsharp