我正在开发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. 在WPF应用程序中托管WCF服务
- 3. 在Web应用程序中托管Wcf服务库
- 4. 在ASP.NET MVC Web应用程序中托管WCF服务
- 5. 在同一Web应用程序中托管WCF服务和WebAPI
- 6. WCF服务托管在Windows服务+ Silverlight + Silverlight应用程序
- 7. 在WPF/Surface应用程序内托管WPF/Surface应用程序
- 8. 托管Web服务/ WCF服务?
- 9. 托管的Windows服务中托管的WCF服务使用WCF服务应用程序连接
- 10. 在web项目中托管WCF服务
- 11. 在iPad中托管WCF Web服务(MonoTouch)
- 12. 在IIS中托管WCF应用程序
- 13. MaxReceivedMessageSize在WCF的控制台应用程序托管服务
- 14. 在ASP.NET MVC应用程序中托管WCF服务?
- 15. 在Sitecore 7应用程序中托管WCF服务
- 16. 在ASP.NET MVC 3应用程序中托管WCF数据服务?
- 17. 托管在控制台应用程序中的WCF服务
- 18. 如何在应用程序上托管wcf服务器?
- 19. Web服务器来托管我的MVC4 Web应用程序
- 20. 托管WCF服务
- 21. WCF服务托管
- 22. 从Windows 8应用程序调用本地Web服务(自托管WCF)
- 23. Web应用程序托管
- 24. 从远程服务器托管WCF Web服务
- 25. 对WCF托管REST Web服务与IIS
- 26. WCF Web服务托管后出错
- 27. 在本地服务器上托管Web应用程序
- 28. 在Android应用程序中托管Web服务
- 29. 无法连接到托管应用程序托管的多个WCF服务
- 30. 在Azure中托管一个Web应用程序,该应用程序使用内部Web服务和ActiveMQ
你有没有看自托管的应用程序内的服务? – Tim 2012-02-26 18:47:51
你有什么进展吗?我有同样的情况。 – Simon 2012-04-23 14:39:08
请参阅下面的答案。 – Tomer 2012-04-23 20:00:17