我已經研究過這一天了,現在正在轉向您的專家來諮詢您的意見。自行託管WCF無配置 - 難以理解設置端點
我有REST服務是主要的IIS託管服務。
此服務需要與32位非託管的.dll接口。爲了做到這一點,我正在採取一種常用的方法,即創建一個自己託管的服務並打電話給它。
有了這樣的背景,我有一個時間讓自己託管的人工作。
這裏要說的是作品中的代碼:
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8080/theSvc");
Uri mexUri = new Uri("http://localhost:8080/theSvc/mex");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(ImgService), baseAddress))
{
// var wsHttpBinding = new WSHttpBinding();
// wsHttpBinding.MaxReceivedMessageSize = int.MaxValue;
// host.AddServiceEndpoint(typeof(IImgService), wsHttpBinding, baseAddress);
// Enable metadata publishing.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetUrl = mexUri;
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
// Open the ServiceHost to start listening for messages. Since
// no endpoints are explicitly configured, the runtime will create
// one endpoint per base address for each service contract implemented
// by the service.
host.Open();
Console.WriteLine("The service is ready at {0}", baseAddress);
Console.WriteLine("Press <Enter> to stop the service.");
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
}
}
現在...如果我爲了增加maxreceivedMessageSize從using語句刪除baseAddress取消註釋這些行,我再也不能添加到參考服務:
所以更改此設置:
using (ServiceHost host = new ServiceHost(typeof(ImgService), baseAddress))
要這樣:
using (ServiceHost host = new ServiceHost(typeof(ImgService)))
,並取消本:
// var wsHttpBinding = new WSHttpBinding();
// wsHttpBinding.MaxReceivedMessageSize = int.MaxValue;
// host.AddServiceEndpoint(typeof(IImgService), wsHttpBinding, baseAddress);
,我收到的錯誤:
... - >本地主機
There was an error downloading 'http://...:8080/theSvc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 'http://...:8080/theSvc'.
Metadata contains a reference that cannot be resolved: 'http://...:8080/theSvc'.
If the service is defined in the current solution, try building the solution and adding the service reference again.
像其他人說的帖子在這裏...我處於困境中。任何幫助真的很感激。
您是否考慮過WCF的替代方法,與簡單的HTTP服務相比,這種方法往往比較複雜? – Simone 2014-09-12 19:23:05
如果能夠滿足我的需求,我會100%滿意。 我覺得我和WCF的服務非常接近,如果我能把這個最後的配置部分弄清楚 – tronious 2014-09-12 19:26:38
嗯,你已經被警告過:)真的,我不能幫你,我小心翼翼地避免WCF – Simone 2014-09-12 19:28:48