2
我使用下面的代碼與REST服務進行通信的內部REST服務:溝通與REST服務
[ServiceContract()]
interface ISomeService
{
[OperationContract()]
[WebGet()]
bool DoSomething();
}
WebHttpBinding binding = new WebHttpBinding();
ChannelFactory<ISomeService> channelFactory = new ChannelFactory<ISomeService>(binding, "http://localhost:12000");
channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());
ISomeService service = channelFactory.CreateChannel();
service.DoSomething();
它工作正常,在簡單的測試應用程序,但在我的實際應用中,我想裏面叫它我自己的REST服務:如果對我的REST服務進行了調用,我的服務應該調用另一個REST服務。
而且事情變得很奇怪。在這種情況下,上面的代碼不起作用,因爲如果將它放在服務方法中,它將發送POST請求而不是GET請求,這當然會導致「方法不允許」錯誤。我的代碼中沒有任何屬性WebInvoke。
[ServiceContract()]
class MainService
{
[OperationContract()]
[WebGet()]
public void Test()
{
CallDoSomething(); // code from above: Sends POST instead of GET request
}
}
豈是HTTP請求方法的變化?
DORS'ISomeService'有'[WebGet]'其運作?在客戶端。 – 2010-09-17 17:56:40
是的,它有雙方的[WebGet] :)我添加了一個演示到開始帖子。 – pdb 2010-09-17 18:15:58