기본적인 형태의 프로젝트 구조
계약된 웹서비스를 만들기 위한 인터페이스
using System.ServiceModel;
using System.ServiceModel.Description;
namespace IChannel
{
[ServiceContract]
public interface IHelloWorld
{
[OperationContract]
string Hellworld();
}
}
웹서비스(서버측)
using IChannel;
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1 , IChannel.IHelloWorld
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
string IHelloWorld.Hellworld()
{
return "TEST MODE";
}
}
}
클라이언트에서 호출
Icannerl 이 참조되어져 있습니다.
string uri = "http://localhost:49724/Service1.svc";
ServiceEndpoint ep = new ServiceEndpoint(ContractDescription.GetContract(typeof(IChannel.IHelloWorld)), new wsHttpBinding(), new EndpointAddress(uri));
ChannelFactory<IChannel.IHelloWorld> factory = new ChannelFactory<IChannel.IHelloWorld>(ep);
IChannel.IHelloWorld proxy = factory.CreateChannel();
string result = proxy.Hellworld();
(proxy as IDisposable).Dispose();
MessageBox.Show(result);
서버측 웹컨피그 수정
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MarinerERP.WebService.DataService.InsaServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MarinerERP.WebService.DataService.InsaServiceBehavior"
name="MarinerERP.WebService.DataService.InsaService">
<endpoint address="" binding="wsHttpBinding" contract="IChannel.IHelloWorld "> //인터페이스로 맞추어주어야 합니다.
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
contract 는 웹서비스와 클라이언트와의 계약이기 때문에 꼭 맞추어 주세요!
'C#.NET 웹서비스' 카테고리의 다른 글
[MSDN]WCF 서비스호스팅 (0) | 2009.12.23 |
---|---|
[N- 티어]계층 응용 프로그램의 데이터 검색,수정,삭제 (LINQ to SQL) (0) | 2009.12.21 |
wcf 웹서비스로 전달할 클래스 만들기 (0) | 2009.12.17 |
[WCF 디버깅]의 TRY{}CATCH{}예외처리를 받고싶으면?! (0) | 2009.12.10 |
[WCF]Learn The ABCs Of Programming Windows Communication Foundation (0) | 2009.12.10 |
Beginner's Guide to Windows Communication Foundation (0) | 2009.12.10 |
IMetadataExchange 인터페이스 (0) | 2009.12.09 |
net.tcp 프로토콜을 통해 통신하는 서비스를 활성화하기 (0) | 2009.12.09 |
WAS(Windows Process Activation Service) (0) | 2009.12.07 |
[asp.net] 최대 요청 길이를 초과했습니다. (0) | 2009.04.23 |