我正在開發WPF應用程序。作爲應用程序的一部分,我需要通過另一個iOS應用程序接收一些圖像。所以我寫了WCF REST服務和iOS,我只能在將服務定義爲IIS的一部分時才能將圖像發送到Web服務。
我需要發生的事情是:當WPF應用程序啓動時,Web服務也將啓動,並公開iOS設備的端口號以發送圖像並在啓動時「喚醒」WPF應用程序。 有什麼想法?在WPF應用程序內託管WCF Web服務
0
A
回答
1
是的,我做到了。事實上,正如Tim提到的,那正是我自己託管的服務。 你可以看看下面的視頻(還有很多其他的,請看鏈接)。 http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Building-RESTful-Services-with-WCF/
這裏有我的WCF項目完整的文件(如電影提),我希望這將讓你開始.. 只是注意,同樣重要的是在您的電腦打開特定的端口啓用傳入的HTTP通信。看看WCF ServiceHost access rights。
Eval.cs
[DataContract]
public class Eval
{
public string id;
[DataMember]
public string Submitter;
[DataMember]
public DateTime Timesent;
[DataMember]
public string Comments;
}
IEvalService.cs
[ServiceContract]
public interface IEvalService
{
[WebInvoke(Method="POST", UriTemplate = "evals")]
[OperationContract]
void SubmitEval(Eval i_Eval);
[WebGet(UriTemplate = "evals")]
[OperationContract]
List<Eval> GetEvals();
[WebGet(UriTemplate="eval/{i_Id}")]
[OperationContract]
Eval GetEval(string i_Id);
[WebGet(UriTemplate = "evals/{i_Submitter}")]
[OperationContract]
List<Eval> GetEvalsBySubmitters(string i_Submitter);
[WebInvoke(Method = "DELETE", UriTemplate = "eval/{i_Id}")]
[OperationContract]
void RemoveEval(string i_Id);
[WebGet(UriTemplate = "GetLastPhoto", BodyStyle = WebMessageBodyStyle.Bare)]
Stream GetLastPhoto();
[OperationContract] // this web address is for receiving the image for the iOS app.
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "TestPost")]
string TestPost(Stream stream);
}
EvalService.cs
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class EvalService : IEvalService
{
private List<Eval> m_Evals = new List<Eval>();
private int evalCount = 0;
private string k_FilePath = "C:\\ImageUpload\\";
public static event Action<LogicImage> ImageLoaded;
public void SubmitEval(Eval i_Eval)
{
i_Eval.id = (++evalCount).ToString();
m_Evals.Add(i_Eval);
}
public List<Eval> GetEvals()
{
return m_Evals;
}
public Eval GetEval(string i_Id)
{
return m_Evals.First(e => e.id.Equals(i_Id));
}
public List<Eval> GetEvalsBySubmitters(string i_Submitter)
{
if (i_Submitter == null && i_Submitter.Equals(""))
{
return null;
}
else
{
return m_Evals.Where(e => e.Submitter == i_Submitter).ToList();
}
}
public void RemoveEval(string i_ID)
{
throw new NotImplementedException();
}
public Stream GetLastPhoto()
{
Image image = Image.FromFile("C:\\ImageUpload\\014.png");
MemoryStream ms = new MemoryStream(imageToByteArray(image));
return ms;
}
public string TestPost(Stream stream)
{
HttpMultipartParser parser = new HttpMultipartParser(stream, "image");
if (parser.Success)
{
if (parser.Success)
{
// deal with exceptions..
//
File.WriteAllBytes(k_FilePath + parser.Filename, parser.FileContents);
if (ImageLoaded != null)
{
ImageLoaded.Invoke(new LogicImage(){FileName = parser.Filename, Location = k_FilePath});
}
}
}
return "test";
}
public static byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}
public class LogicImage
{
public string FileName { get; set; }
public string Location { get; set; }
}
最後但並非最不重要的** **的App.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="ImageRecevierWebService.EvalService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/ImageRecevierWebService/Service1/"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="wsHttpBinding" contract="ImageRecevierWebService.IEvalService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
相關問題
- 1. MVC Web應用程序內託管的WCF服務
- 2. 在Web應用程序中託管Wcf服務庫
- 3. 在ASP.NET MVC Web應用程序中託管WCF服務
- 4. WCF服務託管在Windows服務+ Silverlight + Silverlight應用程序
- 5. 在WPF/Surface應用程序內託管WPF/Surface應用程序
- 6. 託管Web服務/ WCF服務?
- 7. 在iPad中託管WCF Web服務(MonoTouch)
- 8. 在web項目中託管WCF服務
- 9. 在ASP.NET MVC應用程序中託管WCF服務?
- 10. 在Sitecore 7應用程序中託管WCF服務
- 11. 如何在應用程序上託管wcf服務器?
- 12. MaxReceivedMessageSize在WCF的控制檯應用程序託管服務
- 13. 在ASP.NET MVC 3應用程序中託管WCF數據服務?
- 14. 在應用程序中託管WCF服務
- 15. 託管WCF服務
- 16. Web應用程序託管
- 17. 在Android應用程序中託管Web服務
- 18. 在本地服務器上託管Web應用程序
- 19. WCF Web服務託管後出錯
- 20. 對WCF託管REST Web服務與IIS
- 21. 在託管WCF服務WAS
- 22. 64位Windows服務器上的WCF自託管應用程序
- 23. 託管Silverlight應用程序頁面與WCF服務的錯誤
- 24. WCF應用程序託管服務故障狀態異常?
- 25. 從IIS中託管的ASP.NET Web應用程序接收WCF回調服務
- 26. 託管自己的web應用程序的Node.js或使用託管服務
- 27. WPF應用程序託管WCF訪問衝突
- 28. 由WPF應用程序管理的WCF服務?
- 29. 無法引用WCF服務託管在AppFabric上的WCF Web服務
- 30. 以xamarin格式在Web應用程序中託管wcf
你有沒有看自託管的應用程序內的服務? – Tim 2012-02-26 18:47:51
你有什麼進展嗎?我有同樣的情況。 – Simon 2012-04-23 14:39:08
請參閱下面的答案。 – Tomer 2012-04-23 20:00:17