0% found this document useful (0 votes)
45 views10 pages

WCF Calculator Service Implementation

Uploaded by

vrund3626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views10 pages

WCF Calculator Service Implementation

Uploaded by

vrund3626
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Iservice1.

cs

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace Lab4
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the
interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);

// TODO: Add your service operations here


}

// Use a data contract as illustrated in the sample below to add composite types to
service operations.
// You can add XSD files into the project. After building the project, you can directly use
the data types defined there, with the namespace "[Link]".
}

[Link]

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace Lab4
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the
class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return [Link]("You entered: {0}", value);
}
}
}

[Link]

<?xml version="1.0" encoding="utf-8" ?>


<configuration>

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<[Link]>
<compilation debug="true" />
</[Link]>
<!-- When deploying the service library project, the content of the config file must be added to
the host's
[Link] file. [Link] does not support config files for libraries. -->
<[Link]>
<services>
<service name="Lab4.Service1">
<host>
<baseAddresses>
<add baseAddress = "[Link] />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="Lab4.IService1">
<!--
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 values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
</[Link]>

</configuration>
Client Code

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_click(object sender, EventArgs e)
{
ServiceReference1.Service1Client sc=new ServiceReference1.Service1Client();
[Link]=[Link]([Link]([Link]));
}
}
}

Calculator

[Link]
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace Calculator_Lab4
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the
interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
int Add(int a,int b);

[OperationContract]
int Sub(int a,int b);

[OperationContract]
int mul(int a,int b);

[OperationContract]
int div(int a,int b);
}

// Use a data contract as illustrated in the sample below to add composite types to
service operations.
// You can add XSD files into the project. After building the project, you can directly use
the data types defined there, with the namespace "Calculator_Lab4.ContractType".

[Link]

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace Calculator_Lab4
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the
class name "Service1" in both code and config file together.
public class Service1 : IService1
{
public int Add(int a, int b)
{
return a + b;
}
public int Sub(int a,int b)
{
return (a - b);
}
public int mul(int a,int b)
{
return a * b;
}
public int div(int a,int b)
{
return a / b;
}
}
}
Client Code

using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

namespace CalcClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Sum
private void btnclick1(object sender, EventArgs e)
{
ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
int a = [Link]([Link]);
int b= [Link]([Link]);
[Link] = [Link](a, b).ToString();

}
//Sub
private void btnclick2(object sender, EventArgs e)
{
ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
int a = [Link]([Link]);
int b = [Link]([Link]);
[Link] = [Link](a, b).ToString();
}
//Mul
private void btnClick3(object sender, EventArgs e)
{
ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
int a = [Link]([Link]);
int b = [Link]([Link]);
[Link] = [Link](a, b).ToString();
}
//Div
private void btnClick4(object sender, EventArgs e)
{
ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
int a = [Link]([Link]);
int b = [Link]([Link]);
[Link] = [Link](a, b).ToString();
}
}
}

You might also like