Skip to content

Commit

Permalink
compatibility to net472, moved code to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesmayer committed Nov 18, 2018
1 parent 0d1b606 commit 9818279
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
49 changes: 49 additions & 0 deletions ReconnectFritz/FritzReconnect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace ReconnectFritz
{
using System.IO;
using System.Net;
using System.Text;

public class FritzReconnect
{
private string xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope\">" +
"<s:Body>" +
"<u:ForceTermination xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\" />" +
"</s:Body>" +
"</s:Envelope>";

public string ReconnectFritzBox()
{
string resulXmlFromWebService = null;

var webRequest = WebRequest.Create("http://fritz.box:49000/igdupnp/control/WANIPConn1");
var httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPACTION", "urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.ContentLength = xmldata.Length;

using (var requestStream = httpRequest.GetRequestStream())
{
//Create Stream and Complete Request
using (var streamWriter = new StreamWriter(requestStream, Encoding.ASCII))
{
streamWriter.Write(xmldata);
streamWriter.Close();

//Get the Response
var wr = (HttpWebResponse)httpRequest.GetResponse();
using (var srd = new StreamReader(wr.GetResponseStream()))
{
resulXmlFromWebService = srd.ReadToEnd();
}
}
}

return resulXmlFromWebService;
}
}
}
46 changes: 1 addition & 45 deletions ReconnectFritz/Program.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,10 @@
namespace ReconnectFritz
{
using System.IO;
using System.Net;
using System.Text;

class Program
{
private static string xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope\">" +
"<s:Body>" +
"<u:ForceTermination xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\" />" +
"</s:Body>" +
"</s:Envelope>";

static void Main(string[] args)
{
ReconnectFritzBox();
}

private static string ReconnectFritzBox()
{
string resulXmlFromWebService = null;

var webRequest = WebRequest.Create("http://fritz.box:49000/igdupnp/control/WANIPConn1");
var httpRequest = (HttpWebRequest)webRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "text/xml; charset=utf-8";
httpRequest.Headers.Add("SOAPACTION", "urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination");
httpRequest.ProtocolVersion = HttpVersion.Version11;
httpRequest.Credentials = CredentialCache.DefaultCredentials;
httpRequest.ContentLength = xmldata.Length;

using (var requestStream = httpRequest.GetRequestStream())
{
//Create Stream and Complete Request
using (var streamWriter = new StreamWriter(requestStream, Encoding.ASCII))
{
streamWriter.Write(xmldata);
streamWriter.Close();

//Get the Response
var wr = (HttpWebResponse)httpRequest.GetResponse();
using (var srd = new StreamReader(wr.GetResponseStream()))
{
resulXmlFromWebService = srd.ReadToEnd();
}
}
}

return resulXmlFromWebService;
new FritzReconnect().ReconnectFritzBox();
}
}
}
2 changes: 1 addition & 1 deletion ReconnectFritz/ReconnectFritz.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
</PropertyGroup>

</Project>

0 comments on commit 9818279

Please sign in to comment.